title: Cookie not working with Login System CodeIgniter
body: <p>I have implemented a basic login system using CodeIgniter. I am using the <code>sessions</code> library to control access to a members only section. I can log in and view this area no problem. However when I delete my cookies and refresh the members only section page I can still see the content. I am not displaying a login message to the user.</p>
  
  <p>I don't know why this is happening. Any ideas?</p>
  
  <p>This is my Site.php controller</p>
  
  <pre><code>class Site extends CI_Controller{
  
  function _construct(){
      parent::_construct();
      $this-&gt;is_logged_in();
  }
  
  function members_area(){
      $this-&gt;load-&gt;view('members_area');
  }
  
  function is_logged_in(){
      $is_logged_in = $this-&gt;session-&gt;userdata('is_logged_in');
      if(!isset($is_logged_in) || $is_logged_in != true){
          echo 'You need to login to access this page. &lt;a href="../login"&gt;Login&lt;/a&gt;';
          die();
  }
  </code></pre>
  
  <p>}
  }</p>
  
  <p>This is my login.php Controller</p>
  
  <pre><code>class Login extends CI_Controller{
  function index(){
      $data['main_content'] = 'login_form';
      $this-&gt;load-&gt;view('includes/template', $data);
  }
  
  
  function validate_credentials(){
      $this-&gt;load-&gt;model('membership_model');
      $query = $this-&gt;membership_model-&gt;validate();
      if($query){//if credentials validated
          $data = array(
              'username' =&gt; $this-&gt;input-&gt;post('username'),
              'is_logged_in' =&gt; true
              );
  
          $this-&gt;session-&gt;set_userdata($data);
          redirect('site/members_area');
      }
  
      else{//If not validated re load login form
          $this-&gt;index();
      }
  }
  
  function signup(){
      $data['main_content'] = 'signup_form';
      $this-&gt;load-&gt;view('includes/template', $data);
  
  }
  
  function create_member(){
      $this-&gt;load-&gt;library('form_validation');
      //field name, error message, validation rules
      $this-&gt;form_validation-&gt;set_rules('first_name', 'Name', 'trim|required');
      $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'trim|required');
      $this-&gt;form_validation-&gt;set_rules('email_address', 'Email Address', 'trim|required|valid_email');
      $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|min_length[4]');
      $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
      $this-&gt;form_validation-&gt;set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
  
      if($this-&gt;form_validation-&gt;run() == FALSE){
          $this-&gt;signup();
      }
      else{
          //create a new row in db 
          $this-&gt;load-&gt;model('membership_model');
          if($query = $this-&gt;membership_model-&gt;create_member()){
              //Info entered
              $data['main_content'] = 'signup_successful';
              $this-&gt;load-&gt;view('includes/template', $data);
          }
          else{
              $this-&gt;load-&gt;view('signup_form');
          }
      }
  
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the code that should be executed if a session does not exist. It is found in the <code>site.php</code> file.</p>
  
  <pre><code>if(!isset($is_logged_in) || $is_logged_in != true){
          echo 'You need to login to access this page. &lt;a href="../login"&gt;Login&lt;/a&gt;';
          die();
  </code></pre>
  
  <p>Any help is much appreciated!</p>