I’ve been recently developing a very large scale website and back end system for a client and during the development process we came across and very annoying yet common issue that really spoils the user experience. When data is posted from one page to another and the user navigates back using the “Back” button in their browser, you get a warning page saying that the page has expired. Not only is this very annoying for the user, but could potentially turn them off from using the site altogether.
So what’s the solution? Well there are a couple of things we can do to help the problem, but the only real way to get around this is to use a header redirect once the form has been posted. Let’s look at an example.
So you have a form like below and you want the users name to be stored in a session variable.
<form action=”step_2.php” method=”post”>
<input type=”text” id=”users_name” name=”users_name” />
<input type=”submit” id=”submit” name=”submit” value=”SUBMIT” />
</form>
When the SUBMIT button is then pressed a PHP script is called to store the users_name in a SESSION variable, like so:
<?php
if (isset($_POST['users_name'])) {
$_SESSION['users_name'] = $_POST['users_name'];
}
?>
The one thing that is missing from this script is the header redirect. This will redirect the page to the page of your choice and will eliminate the Page Expired issue. So to do this simply change the above script to:
<?php
if (isset($_POST['users_name'])) {
$_SESSION['users_name'] = $_POST['users_name'];
header(‘Location: step_2.php’);
}
?>
Perfect!

01926 411 827