如何通过应用程序记住用户的进度? [英] How to memorize user's progress through the application?

查看:29
本文介绍了如何通过应用程序记住用户的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临着一个我没能解决的架构问题.我正在用 PHP 和 Javascript 开发一个小游戏,我需要保存用户的进度.现在,问题是 PHP 无法确定用户何时赢得关卡:它是在 Javascript 中完成的.有没有办法在用户赢得关卡时保存他的进度?

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 级的访问权限.如果他尝试访问第 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 可以帮助您,但不是必需的.这取决于你的游戏是如何设置的.但是如果他们完成了关卡,则需要通知服务器.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆