将变量从一页传递到下一页
我正在开发问题与解答;在网站的答案网站上,向用户显示页面上的五个难题,并在用户尝试页面上的问题时使用JavaScript计算分数.分数保存在Javascript变量score
中.我有这样的分页系统:
I am developing a Question & Answer website where a user is presented five puzzles on a page and the score is calculated using JavaScript as he attempts the questions on the page. The score is saved in a Javascript variable score
. I have a paging system like this:
现在,当用户单击 3 时,我想将变量score
发送到下一页,每个这样的页面上都有require scoreUpdateInDatabase.php
,以便获得上一页的得分该数据库永久存在,下面的PHP脚本向他提出了接下来的5个问题.
Now when the user clicks on 3 I want to send the variable score
to the next page, where I have require scoreUpdateInDatabase.php
on each such page such that the score of previous page is made permanent to the databse and the following PHP script presents him the next 5 questions.
如何安全地传递该score
变量?我不能使用GET
,因为用户会对其进行修改.即使可以修改POST
数据,但我仍然对POST
感到满意,但我只希望获得最低的安全性.
How can I pass that score
variable in secure way? I can't use GET
because the user will modify it. I am satisfied with POST
if this can be used, even though POST
data can be modified but I just want minimal security.
P.S..请不要建议拨打AJAX电话,我会在一侧发送score
,而在返回时会发出接下来的5个问题.我不想使用AJAX刷新内容,因为它是
P.S. Please do not suggest making AJAX call where in one side I will send score
and while returning carries next 5 questions. I don't want to use AJAX to refresh content because it is not SEO friendly.
最简单的解决方案是基于Cookie的解决方案.将值写入会话cookie并读取它.
The simplest solution would be cookie based. Writing the value to a session cookie and the reading it.
您可以使用 jquery cookie .如果需要,还可以选择要求使用https.
You could use jquery cookie. It also gives you the option to require https if desired.