简体   繁体   English

如何处理浏览器后退按钮以获取动态内容

[英]How to handle browser back button for dynamic content

I'm writing a PHP app which presents people with a form to fill out and submit. 我正在编写一个PHP应用程序,该程序向人们展示了要填写和提交的表单。

Once the user submits the form, things change in the database and the form should become inaccessible to the user. 一旦用户提交了表单,数据库中的内容就会发生变化,并且用户应该无法访问该表单。

If, however, the user presses the back button after submitting the form, they can see it again. 但是,如果用户在提交表单后按了“后退”按钮,则他们可以再次看到它。 I have code in the back end to prevent a user from being able to re-submit an already submitted form, however ideally if the user presses the back button, they will get the same message as if they were to just navigate to it outright: A message is shown on the screen saying that this form has already been submitted and is now unavailable. 我在后端有代码,以防止用户能够重新提交已经提交的表单,但是理想情况下,如果用户按下“后退”按钮,他们将获得与直接导航到该表单相同的消息:屏幕上会显示一条消息,说明此表单已提交,现在不可用。

Aside from an AJAX call to the back-end to check if the form has already been submitted, and redirect the user to the "form submitted and now unavailable" message, is there any other (better?) way of handling this? 除了对后端的AJAX调用以检查是否已提交表单,并将用户重定向到“表单已提交但现在不可用”消息外,还有其他(更好的方法)来处理此问题吗?

Since this will only be used internally on a SOE, I only need it to work on IE8+. 由于这只会在SOE内部使用,因此我只需要它在IE8 +上即可使用。

You can consider adding this information to session/cookie. 您可以考虑将此信息添加到会话/ cookie。 Alternatively if you have authentication system, you can store this information in the database. 或者,如果您具有身份验证系统,则可以将此信息存储在数据库中。 Probably the first option is easier and sufficient. 第一种选择可能更容易且足够。

so basically before displaying the form you check if the cookie alreadySubmitted is 1. If yes - error message, otherwise - form. 因此,基本上在显示表单之前,您要检查cookie hasSubmitted是否为1。如果是,则返回-错误消息,否则-表单。 When you submit the form, just set this cookie to alreadySubmitted. 提交表单时,只需将此Cookie设置为hasSubmitted。

However be aware, that if someone deletes cookie, he will be able to trick your system. 但是请注意,如果有人删除cookie,他将能够欺骗您的系统。

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

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