title: CodeIgniter login session
body: <p>I'm new in CodeIgniter and I tried to create a login system on my website. When I try to enter on page Overview, it sends me on login page but after I put my correct email and password nothing happens.</p>
  
  <p><strong>Login.php - controller</strong></p>
  
  <pre><code>    &lt;?php if ( ! defined('BASEPATH')) exit('No direct script access
  allowed');
       class Login extends CI_Controller {
        function __construct()
        {
          parent::__construct();
        }
  
        function index()
        {
          $this-&gt;load-&gt;helper(array('form'));
          $this-&gt;load-&gt;view('login');
        }
  
       }
      ?&gt;
  </code></pre>
  
  <p><strong>Overview.php - controller</strong></p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Overview extends CI_Controller {
  
   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('overview', $data);
     }
     else
     {
       //If no session, redirect to login page
       redirect('login', 'refresh');
     }
   }
  
   function logout()
   {
     $this-&gt;session-&gt;unset_userdata('logged_in');
     session_destroy();
     redirect('home', 'refresh');
   }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>VerifyLogin.php - controller</strong></p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class VerifyLogin extends CI_Controller {
  
   function __construct()
   {
     parent::__construct();
     $this-&gt;load-&gt;model('user','',TRUE);
   }
  
   function index()
   {
     //This method will have the credentials validation
     $this-&gt;load-&gt;library('form_validation');
  
     $this-&gt;form_validation-&gt;set_rules('email', 'E-mail', 'trim|required|xss_clean');
     $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
  
     if($this-&gt;form_validation-&gt;run() == FALSE)
     {
       //Field validation failed.  User redirected to login page
       $this-&gt;load-&gt;view('login');
     }
     else
     {
       //Go to private area
       redirect('home', 'refresh');
     }
  
   }
  
   function check_database($password)
   {
     //Field validation succeeded.  Validate against database
     $username = $this-&gt;input-&gt;post('username');
  
     //query the database
     $result = $this-&gt;user-&gt;login($username, $password);
  
     if($result)
     {
       $sess_array = array();
       foreach($result as $row)
       {
         $sess_array = array(
           'id' =&gt; $row-&gt;id,
           'username' =&gt; $row-&gt;username
         );
         $this-&gt;session-&gt;set_userdata('logged_in', $sess_array);
       }
       return TRUE;
     }
     else
     {
       $this-&gt;form_validation-&gt;set_message('check_database', 'Invalid username or password');
       return false;
     }
   }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Login.php - views</strong></p>
  
  <pre><code>&lt;div class="container"&gt;
  &lt;div class="row"&gt;
  &lt;div class="col-md-4 col-md-offset-4 well"&gt;
  &lt;form role="form" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post" name="loginform"&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Login&lt;/legend&gt;
  &lt;div class="form-group"&gt;
  &lt;label for="name"&gt;Email&lt;/label&gt;
  &lt;input type="text" name="email" placeholder="Your Email" required class="form-control" /&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
  &lt;label for="name"&gt;Password&lt;/label&gt;
  &lt;input type="password" name="password" placeholder="Your Password" required class="form-control" /&gt;       
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
  &lt;input type="submit" name="login" value="Login" class="btn btn-primary" /&gt;
  &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;span class="text-danger"&gt;&lt;?php if (isset($errormsg)) { echo $errormsg; } ?&gt;&lt;/span&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks and I hope somene will give me a solution.</p>