Answer the question
In order to leave comments, you need to log in
Confirm Form Resubmission after POST request in Google Chrome
As you know, after the POST form, it is desirable to make a redirect to protect against resubmission of data.
But in chrome (versions 25 and 26) for some reason it doesn’t work, it’s strange that I haven’t seen this before, apparently they broke it recently, or I don’t ...
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//setcookie('post', 1, time()+604800);
header('Location: '.$_SERVER['REQUEST_URI'], true, 301);
}
//elseif (isset($_COOKIE['post'])) {
// setcookie('post', '', time()-604800);
// header('Location: '.$_SERVER['REQUEST_URI'], true, 303);
//}
?>
<form name="form" id="form" method="post" action="<?=$_SERVER['REQUEST_URI']?>">
<input type="submit" id="submit" name="submit" value="Submit" />
</form>
Answer the question
In order to leave comments, you need to log in
Before blaming Chrome for "wrong" behavior, it's worth looking at the RFC, and how browsers should behave in such a situation:
www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2
> Note: When automatically redirecting a POST request after receiving a 301 status code, some existing HTTP/1.0 user agents will erroneously change it into a GET request.
It turns out that this behavior complies with the HTTP standard. No wonder, because Chrome is developed (unlike competing browsers) by the best programmers in the world.
Weird, it doesn't really work. True, redirects to pages other than the one to which the form was sent work quite normally.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question