简体   繁体   English

在没有 javascript 的情况下防止页面刷新后变量更新

[英]Prevent variable update after page refresh without javascript

A friend of mine is developing a web application that's more of an online learning facility.我的一个朋友正在开发一个 web 应用程序,它更像是一个在线学习工具。 On each page is a set of questions.每页上都有一组问题。 He wants that when the use has answered all the questions on a page and submitted (and taken to the next page for the next set of questions), he shouldn't be able to go back to answer and resubmit those questions again.他希望当用户回答了页面上的所有问题并提交(并转到下一页以获取下一组问题)时,他不应该能够返回 go 来回答并再次重新提交这些问题。 The idea is that "opportunity comes but once".这个想法是“机会来了一次”。

He doesn't want to use javascript because it can be disabled which leaves him with server-side coding.他不想使用 javascript,因为它可以被禁用,这让他只能使用服务器端编码。 He uses PHP.他使用 PHP。

Is there a solution?有解决办法吗?

Maybe use sessions ?也许使用会话 This 'feature' can be really are handy when you want data persistance.当您想要数据持久性时,这个“功能”真的很方便。

There is also the option of using hidden fields to pass the value but in my humble opinion sessions are cleaner.还可以选择使用隐藏字段来传递值,但在我看来会话更干净。

Unless you want to use some sort of database, the easiest way would be to set cookies for the user with PHP.除非您想使用某种数据库,否则最简单的方法是使用 PHP 为用户设置 cookies。 You'd store which questions have already been answered and check that cookie server-side.您将存储已回答的问题并检查该 cookie 服务器端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM