如何记住通过应用程序用户的进展? [英] How to memorize user's progress through the application?
问题描述
我现在面临一个问题,架构我没解决。我开发的PHP和JavaScript的小游戏,我需要保存用户的进度。现在的问题是,PHP无法确定当用户赢得级:它在Javascript中完成的。有什么办法来保存用户的进度时,他胜1平?
I'm facing an architecture problem I didn't manage to solve. I'm developing a little game in PHP and Javascript, and I need to save the user's progress. Now, the problem is that PHP can't determine when the user wins the level: it's done in Javascript. Is there any way to save the user's progress when he wins a level?
例如,当用户胜1平,他被获准进入2级。如果他尝试不读完previous级别访问2级,他被重定向到最后完成了一个。在我的控制器我做以下内容:
For example, when the user wins level 1, he gains access to level 2. If he tries to access level 2 without having completed the previous level, he gets redirected to the last completed one. In my controller I was doing the following:
if (1 !== $id) {
if ($app['session']->get('last_level') !== ($id - 1)) {
// redirect the user
}
}
现在我需要一种方法来存储在 last_level 值到会话,不能由用户进行模拟操作。
Now I need a way to store the last_level value into the session, an operation that can't be simulated by the user.
任何提示?
推荐答案
你会想要做的服务器上的不同 last_level
计算。这样,用户就可以没本事与周围的JavaScript和特制的表格上提交的东西。所以,这取决于你的存储系统是什么(KV存储,数据库,文本文件等),把这些价值在那里,并检索它。
You're going to want to do the different last_level
calculations on the server. That way the user can't hack around with the JavaScript, and submit something on a specially crafted form. So depending on what your storage system is (KV store, Database, Textfile, etc.), put that value in there, and retrieve it.
阿贾克斯可以帮你,但不是必需的。这取决于你的游戏是如何设置的。但是,如果他们完成的水平,服务器需要得到通知。
Ajax can help you out, but isn't necessary. It depends on how your game is set up. But if they complete the level, the server needs to be notified.
这篇关于如何记住通过应用程序用户的进展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!