php - 基于 session 的服务器端数据设置和检索

标签 php javascript jquery web-services model-view-controller

我有一个关于如何处理当前项目的理论问题。这是一个相当简单的匹配测验,使用 JS + PHP。我只是负责服务器上的业务逻辑(答案检查、分数更新),例如大致遵循 MVC 约定。

我当前的设置:

  • HTML + JS 页面允许用户将答案拖放到问题上。成功转换后,问题+答案组合将发送至以下地址:
  • 服务器端 PHP 页面,用于根据 XML 文件检查答案的正确性。我在某个 XML 客户端中返回一些数据,例如真/假以及某个问题的尝试次数。 此外,如果答案正确,我会在服务器上增加一个 session 变量来跟踪用户的分数。

我的问题围绕设置上述 session 变量以跟踪分数的最佳实践。我知道,在计算机关闭、浏览器意外关闭等情况下,更持久的设置很可能是更好的选择......但严格基于此设置 -

  1. 这是一种存储最终插入数据库的分数的安全方法吗?
  2. 我最终也必须在游戏结束时(甚至游戏中期)从服务器上拉低分数。我应该创建一个简单的“getter”PHP 页面来拉低分数,然后访问 session 变量并将其发送到客户端吗?
  3. 目前,用户实际上可以访问 php 服务器端页面,因为它与实际测验位于同一文件夹中。这很可能是禁忌 - 但是隐藏此仅服务器文件以防止用户窥探(无需使用身份验证)的常见做法是什么?

最佳答案

Is this a secure method for storing a score for a final insertion into the database?

这是安全的。但我不明白为什么你不会在数据库中的分数发生变化时更新它们。这样它就会持久化。

I eventually will have to pull the score down from the server at the end of the game (or even mid game, for that matter), as well. Should I create a simple 'getter' PHP page to pull the score down, and just access the session variable and send it to the client?

听起来像是一个计划。

Currently, the user actually has access to the php server-side page becuase it resides in the same folder as the actual quiz. This is moooost likely a no-no - but what is the common practice for hiding this server-only file from the user's prying eyes (without having to use authentication)?

只要文件是 .php 文件并且由网络服务器解析,用户就只能对文件发出请求,仅此而已(如果我理解问题正确的话)。

关于php - 基于 session 的服务器端数据设置和检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11695109/

相关文章:

php - Ajax 实时文本框按下所有 Html 元素

php - 如何将 $_POST 值从 ruby​​ 脚本传递给 php 脚本

javascript - POST Slim 路线不起作用

php - Symfony 安装缺少的供应商库

javascript - 使 onKeyDown 触发 HTML 按钮的 onClick 事件

javascript - 尝试让示例 Node.js 应用程序正常运行

javascript - 附加 html 中的按键

javascript - jQuery Mobile ListView 按钮不可见

javascript - 使用正则表达式验证 keyup 事件的用户输入

jquery - 如果选中复选框,则将类添加到父元素