title: Redirect to old page at logout in PHP
body: <p>I am developing a CMS. I have three scripts, and 2 session variables</p>
  
  <pre><code> $_SESSION['logged']
   $_SESSION['redirect'] 
  </code></pre>
  
  <p>"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 </p>
  
  <pre><code>header(location:index.php)
  </code></pre>
  
  <p>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</p>
  
  <p>"index.php" - checks for user name and password. I successful sets </p>
  
  <pre><code>$_SESSION['logged']=1
  </code></pre>
  
  <p>If  $_SESSION['redirect'] is set it redirects to that page otherwise to deafult page</p>
  
  <p>"logout.php" - Its unsets and destroys the session using</p>
  
  <pre><code>session_unset();
  session_destroy();
  </code></pre>
  
  <p>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']</p>
  
  <pre><code>unset($_SESSION['logged']);
  session_destroy();
  </code></pre>
  
  <p>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 </p>