title: What is the proper way to test CodeIgniter session variable?
body: <p>Take the following code snippet. What is the best way to test to make sure the session variable isn't empty?</p>
  
  <pre><code>&lt;?php if ($this-&gt;session-&gt;userdata('userID')) {
     $loggedIn = 1;
  }
  else {
     $loggedIn = 0;
  } ?&gt;
  </code></pre>
  
  <p>If later in my script, I call the following, the first prints properly, but on the second I receive <em>Message: Undefined variable: loggedIn</em></p>
  
  <pre><code>&lt;?php echo $this-&gt;session-&gt;userdata('userID'));
        echo $loggedIn; ?&gt;
  </code></pre>
  
  <p>I've tried using <code>!empty</code> and <code>isset</code>, but both have been unsuccessful. I also tried doing the if/then statement backwards using <code>if (!($this-&gt;session-&gt;userdata('userID'))</code>, but no dice. Any thoughts? </p>