Take the following code snippet. What is the best way to verify that a session variable is not empty?
<?php if ($this->session->userdata('userID')) {
$loggedIn = 1;
}
else {
$loggedIn = 0;
} ?>
If later in my script, I call the following, the first prints correctly, but on the second I get the message: Undefined variable: loggedIn
<?php echo $this->session->userdata('userID'));
echo $loggedIn; ?>
I tried using !emptyand isset, but both of them were unsuccessful. I also tried to execute the if / then statement back using if (!($this->session->userdata('userID')), but not cubes. Any suggestions?
source
share