Aar*_*ron 3 php mysql xhtml double-submit-prevention
我正试图在我的脚本中纠正双重提交的问题.当我按提交时它只更新一次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>
Run Code Online (Sandbox Code Playgroud)
当您刷新页面时 - POST再次出现
有些浏览器实际上警告过你这件事.
为了防止我这样做:
if (isset($_POST['submitButton'])) {
//do something
//..do all post stuff
header('Location: thisPage.php'); //clears POST
}
<form action = "table.php" method="post">
<label for="submitButton"></label>
<input type="submit" name="submitButton" id="submitButton"
value="Submit Form"/>
</form>
Run Code Online (Sandbox Code Playgroud)
小智 5
我使用会话来防止重新发布。
session_start();
if( isset($_SESSION['your_variable']) &&
$_SESSION['your_variable'] == $_POST['your_variable'] ){
// re-post, don't do anything.
}
else{
$_SESSION['your_variable'] = $_POST['your_variable'];
// new post, go do something.
}
Run Code Online (Sandbox Code Playgroud)