发布/重定向/获取解决方案仅用于刷新页面? [英] Post/Redirect/Get solution just for refreshing the page?

查看:135
本文介绍了发布/重定向/获取解决方案仅用于刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP Post/Redirect/Get解决方案仅对刷新页面有用吗?

PHP Post/Redirect/Get solution is good just for refreshing the page?

如果用户两次单击后退"按钮并重新发送表单,该怎么办?我发现的唯一解决方案是检入数据库是否已发布相同的数据.

What about if the user clicks on the back button twice and resend the form? The only solution I have found is to check in my database if same data is already posted.

在不查询数据库的情况下还有其他解决方案吗?

Is there any other solution without querying the database?

预先感谢您!

推荐答案

PRG也是浏览器后退"按钮支持的理想选择. HTTP重定向替换浏览器历史记录中的URL,而不是添加新条目. 如果您始终应用PRG,即始终从POST返回重定向,则浏览器历史记录将仅包含安全"页面(GET),历史记录中将永远没有POST URL.

PRG is perfect for browser Back button support too. An HTTP redirect replaces the URL in browser history instead of adding a new entry. If you apply PRG consistently, i.e. you always return a redirect from a POST, then browser history will only contain "safe" pages (GET), there will never be a POST URL in the history.

尽管如此,仍然有机会获得重复的表单提交.例如,如果用户双击提交"按钮.因此,如果您想更加安全,则需要一些额外的机制(例如随机数)来防止重复提交.

There is still a chance of getting duplicate form submissions, though. For example if the user double-clicks the submit button. So if you want to be extra safe you need some extra mechanism (e.g. nonce) to prevent double submissions.

这篇关于发布/重定向/获取解决方案仅用于刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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