Search code examples
phpgoogle-chromepost-redirect-get

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.


Solution

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