title: Codeigniter Inputting session data from model for a simple authentication system
body: <p>Trying to put together a simple login authentication.  Been at this for quite sometime, and I can't find where I'm going wrong. Pretty new to Codeigniter and OOP PHP.  I know there are authentication libraries out there, but I'm not interested in using those.</p>
  
  <p>Model:</p>
  
  <pre><code> function login($username, $password){
  
      if ($this-&gt;db-&gt;table_exists($username)){
      $this-&gt;db-&gt;where('username', $username);
      $this-&gt;db-&gt;where('password', $password);
      $query = $this-&gt;db-&gt;get($username); 
  
          if($query-&gt;num_rows &gt;= 1)
          {
          return true;
          $data = array(
              'username' =&gt; $this-&gt;input-&gt;post('username'),
              'login' =&gt; true
              );
              $this-&gt;session-&gt;set_userdata($data);
  
          } 
      }  
      }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>function __construct(){
      parent::__construct();
      $this-&gt;logincheck();
  }
  public function logincheck(){
      if ($this-&gt;session-&gt;userdata('login')){
          redirect('/members');
          }
      }
  </code></pre>
  
  <p>If I just echo from the controller: $this->session->all_userdata(); I get an empty array.  So the problem seems to be that the $data array in the model isn't being stored in the session.</p>