I am developing a CMS. I have three scripts, and 2 session variables
$_SESSION['logged']
$_SESSION['redirect']
"auth.inc.php" - Run every time a user requests a page. It checks if $_SESSION['logged'] is set and equal to 1. If it isn't redirects ti main page using
header(location:index.php)
and the page referrer link is saved in $_SESSION['redirect']. If $_SESSION['logged'] is set inactivity time is less than a required value it redirects to the requested page other wise it redirects to logout.php
"index.php" - checks for user name and password. I successful sets
$_SESSION['logged']=1
If $_SESSION['redirect'] is set it redirects to that page otherwise to deafult page
"logout.php" - Its unsets and destroys the session using
session_unset();
session_destroy();
But I want if user is logged out due to session timeout then after login it should be redirected to old page. Since I was unsetting the session $_SESSION['redirect'] was lost. So instead of using session_unset() I only unset $_SESSION['logged']
unset($_SESSION['logged']);
session_destroy();
but still I am not able to retrieve $_SESSION['redirect'] after session_destroy(). The variable is still not set. How should I redirect to old page after logout due to session expire