On many banking sites you will find that when back or refresh button is pressed the session expires and it shows you a custom page. Well below is a simple PHP code which will do the same. The code is very basic and illustrates just the logic.
Include the below given code in all your scripts.
PHP:
-
// First make sure that the page is not cached
-
-
// Start the session
-
-
// If there is a key in session and there is no key in GET then exit with error.
-
echo "SESSION expired";
-
exit;
-
}
-
-
// If there is a key in GET then validate the key against the key stored in session
-
// Compare the key passed with the one stored in session
-
if ($_GET['key'] != $_SESSION['key']) {
-
echo "SESSION expired";exit;
-
}
-
}
-
-
// Generate a key for next page and store it in session.
-
$_SESSION['key'] = $next_key;
-
-
// Now $next_key is the key which should be passed in all links
-
// Something like <a href="second_page.php?key=$next_key">Secon page</a>
-
// If no key is passed or invalid key is passed then session expire error will be shown
$next_key should be passed in the URL to all scripts.
June 9th, 2008 at 11:48 am
hi !! abbas
nice tut.
thanks.