Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Post/Redirect/Get Failing with Google Chrome

I have tried to implement the POST/REDIRECT/GET design pattern in PHP and it works with Safari but not Google Chrome (for Mac) when I redirect to the exact same page. If I vary the URL slightly (say adding a trailing-slash) it works fine.

Here is a fully functional example:

<?php
if(TRUE === isset($_POST['submit'])) {
    header('Location: http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], true, 303);
    exit();
}?>
<html><head></head><body>
<form action="" method="post"><input type="submit" name="submit" value="submit" /></form>
</body></html>

When I go to the page and click the submit button and then refresh the page, I get a dialog box asking me to confirm the re-submission of the form data. All my searching has said that the above code is the proper way to implement POST/REDIRECT/GET and should work (and it does in Safari) but it doesn't with Chrome on Mac.

like image 710
user2155589 Avatar asked Feb 02 '26 12:02

user2155589


1 Answers

Your code seems okay, I guess what you're experiencing is related to Issue 177855: Wrong handling of Redirection in Chrome 25

like image 120
hendry.fu Avatar answered Feb 05 '26 01:02

hendry.fu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!