What is the proper way to test CodeIgniter session variable? What is the proper way to test CodeIgniter session variable? codeigniter codeigniter

What is the proper way to test CodeIgniter session variable?


Try doing the following instead:

<?php $loggedIn = 0;if ($this->session->userdata('userID') !== FALSE) {   $loggedIn = 1;}?>

If the error continues, you'll need to post more code in case you're calling that variable in another scope.


If your aim is to see whether or not the session variable 'userID' is set, then the following should work:

$this->session->userdata('userID') !== false


Why don't you create a boolean field in your session called is_logged_in and then check like:

if(false !== $this->session->userdata('is_logged_in'))