title: How to redirect user to current page after login (Codeigniter)
body: <p>How do i redirect the user into current page after login?</p>
  
  <blockquote>
    <p>User is reading a news at this URL <code>domain.com/article/news-18565</code> once he click the login button then how do i get currenturl() before going to <code>domain.com/login</code> and after login user should go to <code>domain.com/article/news-18565</code></p>
  </blockquote>
  
  <p><strong>Form.html</strong></p>
  
  <pre><code>&lt;form action="signin" method="post" accept-charset="utf-8"&gt;
          &lt;div class="form-group"&gt;
              &lt;label for=""&gt;Email:&lt;/label&gt;
              &lt;input type="text" name="email" value="" class="form-control form-control-lg"&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label for=""&gt;Password:&lt;/label&gt;
              &lt;input type="password" name="password" value="" class="form-control form-control-lg"&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;input type="submit" name="submit" value="Sign in to your account" class="float-md-right btn btn-primary"&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p><strong>Controller.php</strong></p>
  
  <pre><code>    function index(){
  
      $user_profile = 'user';
      $this-&gt;authModel-&gt;loggedin() == FALSE || redirect($user_profile);
  
      $rules = $this-&gt;authModel-&gt;rules;
      $this-&gt;form_validation-&gt;set_rules($rules);
      if($this-&gt;form_validation-&gt;run() == TRUE){
          if($this-&gt;authModel-&gt;login() == TRUE){
              redirect($user_profile);
          }else{
              $this-&gt;session-&gt;set_flashdata('error', 'That email/password combination does not exist');
              redirect('signin');
          }
      }
   }
  </code></pre>
  
  <p><strong>Model.php</strong></p>
  
  <pre><code>    function login(){
  
      $user = $this-&gt;get_by(array(
              'email' =&gt; $this-&gt;input-&gt;post('email', TRUE),
              'password' =&gt; $this-&gt;hash($this-&gt;input-&gt;post('password'))
          ), TRUE);
  
      if(count($user)){
          $data = array(
              'name' =&gt; $user-&gt;name,
              'email' =&gt; $user-&gt;email,
              'username' =&gt; $user-&gt;username,
              'loggedin' =&gt; TRUE
          );
          $this-&gt;session-&gt;set_userdata($data);
          return TRUE;
      }
  
  }
  </code></pre>