title: redirect back to previous page php
body: <p>I am trying to redirect a user back to the page he/she were after successful login but it is not working right for me.</p>
  
  <p>The problem is that instead of redirecting to the previous page it redirects to account.php.. </p>
  
  <p><strong>Edit</strong>: I already have session started on another page and I am including that file.</p>
  
  <p>The main page... index.php</p>
  
  <pre><code>&lt;?php 
   include_once("models/config.php");
  $_SESSION['page'] = 'index.php';
  ?&gt;
  </code></pre>
  
  <p>And here is login php..</p>
  
  <pre><code> if(isset($_SESSION["page"]) &amp;&amp; is_object($_SESSION["page"])) //check if session exists
                 {
   //Redirect a user to the previous page
   header("Location:".$_SESSION['page']);
                  }
   else{header("Location:account.php");die();}
  </code></pre>