Back Buttons and POST data

An overview of how to stop browser warning messages appearing to users

I had a problem whereby users were returning to a page to which POST data had already been submitted and were receiving an ugly message from the browser saying that their POST data had expired.

Of course there are times when you don’t want users to resubmit POST data but this was a simple search results page which took users to a detail page.

It is not unreasonable that most users don’t know what POST data is and in short I needed a work around.

I saw a few forum entries saying ‘You should tell users not to use the back button!’ With this kind of helpful approach I played around with converting the POST variables to SESSION variables before redirecting to the page that uses the variables. Within ten or so minutes the problem was solved.

Post your form data to a page that processes the variable into a session variable. Then redirect to the page that uses that variable. Following processing the variable is now $_SESSION[‘foo’] rather than $_POST[‘bar’]. This means you can move around as much as you like without triggering the browser message. I do not recommend this for any sensitive information though!

//This eliminates the back button messages of expired POST data by translating POST data in to a SESSION variable and then redirecting

// Start session

// Unset the variable if it exists
if (isset($_POST['bar']))
      $_SESSION['foo'] = $_POST['bar'];

// All done so redirect

The POST data is available at the redirect page and subsequent pages as $_SESSION[‘foo’] and no ugly back button messages will be seen.


Can you help make this article better? You can edit it here and send me a pull request.

See Also