title: how can a page redirect users back to previous page if they try to access the page via url?
body: <p>I have a login page  which won't be accessible if user is already logged in. So login page tries to redirect logged in users back to the page where they came from. </p>
  
  <p>Redirect works if users click a link to go to a page. Problem is  if users are in <code>About</code> page try to access login page via url then the <code>referrer agent</code> won't be set so login page is not redirecting users back to <code>About</code> page, instead it is redirecting back to the <code>base url</code>( i'm using codeigniter and ion auth library).
  login page's redirect code as below:</p>
  
  <pre><code>if($this-&gt;ion_auth-&gt;logged_in())
  {
    redirect($this-&gt;agent-&gt;referrer(), 'refresh');
  }
  </code></pre>
  
  <p>Is it possible to run this code and redirect properly instead of always redirecting to base url?
  When users are logged in i am not showing the link of the login page. So logged in users can only go to login page using url typing, and what i want is if they do they will be redirected back to the page where they came from.</p>