title: Authenticate if user is loggedin and if session and db matches
body: <p>I have this on my pages controller.</p>
  
  <pre><code>protected $auth = array();
  
  function __construct(){
  parent::__construct();
  $this-&gt;auth['result'] = $this-&gt;is_logged_in();
  }
  </code></pre>
  
  <p>and this is my core/base controller located at core folder.</p>
  
  <pre><code>public function is_logged_in(){
  $session = $this-&gt;session-&gt;userdata();
  if(isset($session['logged_in'])){
      return $session;
  }else{ return FALSE; }
  }
  </code></pre>
  
  <p>Is the above codes enough? or am i missing something to do a legitimate authentication?(my first time trying to attempt a user authentication)</p>
  
  <p>Also, would it be okay, if for example.</p>
  
  <p>I added a column '<code>isLoggedin</code>' on my accounts table.</p>
  
  <pre><code>int(1),NULL.
  </code></pre>
  
  <p>and whenever my login function is called and someone successfully logs in, i will also add a value to insert as '<code>isLoggedin</code>' to 1. <code>1=true, 2=false</code>.</p>
  
  <p>So for example in my pages controller, since everytime it loads, it runs the <code>is_logged_in()</code> function in my base controller and would return the session data from there.</p>
  
  <p>I would compare the returned session data from my base controller to the one in my accounts table with the '<code>isLoggedin</code>' col set to 1.</p>
  
  <p>Also, quick question.</p>
  
  <p>In my model, there is a query line: <code>$result = $this-&gt;db-&gt;insert('accounts',$data);</code></p>
  
  <p>if i return <code>$result</code>, does it return TRUE/FALSE based on the success or failure of the query?(if inserted = 1?)</p>
  
  <p>i already did a <code>print_r($result);</code> but it showed a 1. I'm not sure if this 1 means TRUE just in int value. </p>
  
  <p>Also, how do i declare a value boolean? so it would print as TRUE or FALSE. </p>
  
  <p>I already tried, <code>boolean $result</code> but it would return as parse error.</p>