title: login page redirecting again to login page in codeigniter
body: <p>My login page is redirecting me again to my login page and don't know why. I think there have been some issues with my redirect syntax and I'm not able to resolve it so I need your expert help. </p>
  
  <p>My code is below.</p>
  
  <p><strong>Controller file :</strong> 
  Verifylogin_controller.php</p>
  
  <pre><code>&lt;?php
  
  // if(!isset($_SESSION))
  // {
  
  session_start();
  
  // }
  
  class Homelogin_controller extends CI_Controller
  
  {
      public
  
      function __construct()
      {
          parent::__construct();
      }
  
      function index()
      {
          if ($this-&gt;session-&gt;userdata('logged_in'))
          {
              $session_data = $this-&gt;session-&gt;userdata('logged_In');
              $data['username'] = $session_data['username'];
              $this-&gt;load-&gt;view('Home_view', $data);
          }
          else
          {
              redirect('Login_controller', 'refresh');
          }
      }
  
      function logout()
      {
          $this-&gt;session-&gt;unset_userdata('logged_in');
          session_destroy();
          redirect('Homelogin_controller', 'refresh');
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>Model file:</strong> 
  Login_model.php</p>
  
  <pre><code>&lt;?php
  class Login_model extends CI_Model
  
  {
      function login($username, $password)
      {
          $this-&gt;db-&gt;where('username', $username);
          $this-&gt;db-&gt;where('password', $password);
          $query = $this-&gt;db-&gt;get('login');
          if ($query-&gt;num_rows() &gt; 0)
          {
              return true;
          }
          else
          {
              return false;
          }
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>View file</strong></p>
  
  <p>login_view.php</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Login with codeigniter&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt;Simple Login with CodeIgniter&lt;/h1&gt;
  
  &lt;?php echo validation_errors(); ?&gt;
     &lt;?php echo form_open(base_url().'Verifylogin_controller'); ?&gt;
       &lt;label for="username"&gt;Username:&lt;/label&gt;
       &lt;input type="text" size="20" id="username" name="username"/&gt;
      &lt;span&gt;&lt;?php  echo form_error ('username');       ?&gt;                   &lt;/span&gt;
       &lt;br/&gt;
       &lt;label for="password"&gt;Password:&lt;/label&gt;
       &lt;input type="password" size="20" id="passowrd" name="password"/&gt;
       &lt;span&gt;&lt;?php  echo form_error ('password');       ?&gt;                   &lt;/span&gt;
  
       &lt;br/&gt;
       &lt;input type="submit" value="Login"/&gt;
       http://localhost/codeIgniter/CodeIgniter-3.1.4/Verifylogin_controller/login_validation
  &lt;?php
  $this-&gt;session-&gt;flashdata('error');
  ?&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Home_view.php</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Simple Login with CodeIgniter - Private Area&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt;Home&lt;/h1&gt;
     &lt;h2&gt;Welcome &lt;?php echo $this-&gt;session-&gt;userdata('username')   ?&gt;!&lt;/h2&gt;
     &lt;a href="Login_controller/logout"&gt;Logout&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>