刷新php时双重提交
我正在尝试纠正脚本中双重提交的问题。当我按下提交时,它只更新 mysql 一次(这就是我想要的)。但是,当我点击刷新时,它会再次更新 mysql。一旦点击刷新按钮,它似乎就会忽略 if 语句。我该怎么做才能阻止这个,
这是我的代码
if (isset($_POST['submitButton'])) {
//do something
}
<form action = "table.php" method="post">
<label for="submitButton"></label>
<input type="submit" name="submitButton" id="submitButton"
value="Submit Form"/>
</form>
I'm trying to correct the issue of double submit in my script. When I press submit it only updates mysql once(which is what I want). However, when I hit refresh it updates mysql again. It seems to ignore the if statement once the refresh button is hit. What would I do to stop this
here is my code
if (isset($_POST['submitButton'])) {
//do something
}
<form action = "table.php" method="post">
<label for="submitButton"></label>
<input type="submit" name="submitButton" id="submitButton"
value="Submit Form"/>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当您刷新页面时 - POST ISENT AGAIN
有些浏览器实际上会警告您发生这种情况。
为了防止这种情况,我这样做:
When you refresh the page - the POST IS SENT AGAIN
Some browsers actually warn you about that happening.
To prevent that I do:
我使用会话来防止重新发布。
I use a session to keep from reposting.
这是标准行为:当您重新加载页面时,如果该页面已发布,您的浏览器将重放相同的请求(使用 POST)。
为了避免这种情况,您可以使用重定向到同一页面:
这将通过 get 请求重新加载页面。这将防止双重帖子。
This is a standard behavior : when you reload the page, if it was posted, your browser replays the same request (with the POST).
To avoid this, you can use a redirection to the same page, with :
This will reload the page, via a get request. This will prevent double posts.
当你刷新页面时。浏览器再次发布所有数据。因此,在执行某些操作将浏览器再次重定向到同一页面后,会再次发生同样的事情来克服此问题,如下所示
when you refresh the page. browser post all the data again. so the same thing happens again to overcome this after doing something redirect the browser to same page again once like this
我通常不担心这一点,只是依靠用户不会重新发布,除非他们愿意。但是,如果您想禁止它,可以使用随机数。
I usually don't worry about this and just rely on the user NOT re-posting unless they want to. However, if you want to forbid it, you can use a nonce.
http://en.wikipedia.org/wiki/Cryptographic_nonce