将变量从一页传递到下一页 [英] Passing a variable from one page to the next page

查看:97
本文介绍了将变量从一页传递到下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发问题与解答;在网站的答案网站上,向用户显示页面上的五个难题,并在用户尝试页面上的问题时使用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.

这篇关于将变量从一页传递到下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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