Welcome Guest, Not a member yet? Register   Sign In
checking session
#1

[eluser]runrun[/eluser]
Hi,

I am checking session logged in to display user data.

I do like this, when user loin successfully I set session
Code:
$data =array ('logged_in'=>'TRUE');
$this->session->set_userdata($data);

When I check I do like this

Code:
if($this->session->userdata(logged_in) != TRUE){access denied...}

All good, everything works as expected.

But isn't that I have to check like this ?

Code:
if($this->session->userdata(logged_in) != 'TRUE'){access denied...}
#2

[eluser]pistolPete[/eluser]
If you check using !=, the string 'TRUE' will be casted to a boolean value (which will result in TRUE).
If you want to avoid this, you'd have to use !==.

Have a look at language.types.boolean.php.
#3

[eluser]jedd[/eluser]
I get around this problem by just doing this:

Code:
$this->session->set_userdata('login', $login_name);

My logout function unsets that session variable.

Tests are then quite simple:

Code:
if ($this->session->userdata('login')
     // do stuff
else
     // die() or similar




Theme © iAndrew 2016 - Forum software by © MyBB