title: Codeigniter redirect changing on login page
body: <p>I am trying to redirect users to the page they were viewing before attempting to login. For example, if they were looking at baseurl/people/abraham_lincoln and then decided to log in, after they login they would be redirected to baseurl/people/abraham_lincoln. The weird thing is that it is working for some URLs and not others. For some URLs, I am getting "javascript/jsFunctions.js" appended as the URL instead of the URL they were previously on.</p>
  
  <p>At the top of every controller, I set a session variable to do my redirect:</p>
  
  <pre><code>$this-&gt;session-&gt;set_userdata('Redirect', current_url());
  </code></pre>
  
  <p>I am printing this session variable to the top of my controller and at the top of my log in view for testing purposes. Here are a few results I am receiving when I go to my login.</p>
  
  <p><strong>An example of a URL that's working:</strong></p>
  
  <p>URL I attempt to log in from:</p>
  
  <pre><code>baseURL/people
  </code></pre>
  
  <p>What gets printed at the top of my controller as my Redirect session variable:</p>
  
  <pre><code>baseURL/people
  </code></pre>
  
  <p>What gets printed at the top of my log in view as my Redirect session variable:</p>
  
  <pre><code>baseURL/people
  </code></pre>
  
  <p><strong>An example of a URL that's not working:</strong></p>
  
  <p>URL I attempt to log in from:</p>
  
  <pre><code>baseURL/people/abraham_lincoln
  </code></pre>
  
  <p>What gets printed at the top of my controller as my Redirect session variable:</p>
  
  <pre><code>baseURL/people/abraham_lincoln
  </code></pre>
  
  <p>What gets printed at the top of my log in view as my Redirect session variable:</p>
  
  <pre><code>baseURL/people/javascript/jsFunctions.js
  </code></pre>
  
  <p>I'm not sure if it matters, but I am also routing some of these URLs from the routes.php file:</p>
  
  <pre><code>$route['people/(:any)'] = "people/index/$1";
  $route['people/(:any)/(:num)'] = "people/index/$1/$2";
  </code></pre>
  
  <p>I have tried to build my session variable many different ways, including:</p>
  
  <pre><code>current_url()
  base_url().uri_string()
  base_url().$this-&gt;uri-&gt;segment(1)....
  base_url().$this-&gt;uri-&gt;rsegment(1)....
  </code></pre>
  
  <p>If anyone can think of why I'm getting those javascript variables instead of the URL I'm looking for I would appreciate any input.</p>
  
  <p>Thanks!</p>
  
  <p>P.S. I forgot to mention that if I refresh a page that isn't working, for example the abraham_lincoln page, and then go to login, I receive the correct Redirect session variable. Almost like it isn't getting set correctly the first time through, but don't know how I can solve this since I have tried setting the session variable both at the very top and right before the views are loaded.</p>