Welcome Guest, Not a member yet? Register   Sign In
How to check session variable is empty ?
#1

[eluser]suba[/eluser]
pls
help to me
#2

[eluser]Azraf[/eluser]
I am also a newbie, therefore, I can help you very little. But first, you need to clarify your requirement more detail.
#3

[eluser]bigtony[/eluser]
Code:
if (empty($this->session->userdata('my_variable')):
    echo 'The my_session variable is empty.';
endif;
#4

[eluser]affix[/eluser]
bigtony's Method is correct

However I usually do

Code:
if(isset($this->session->userdata('my_var'))
{
   //DO SOMETHING
}
else
{
   //DO SOMETHING ELSE
}

Both methods are correct it just depends on
1. Your personal Oppinion
2. What you will be doing
#5

[eluser]bigtony[/eluser]
affix: You might want to do your own checking on this, but I think you may run into a problem with:
Code:
if(isset($this->session->userdata('my_var'))
etc...
This is because the userdata function returns 'false' if the variable is not set, which means that isset will return true (because 'false' is a set value).
#6

[eluser]suba[/eluser]
hi,
if(empty($this->session->userdata('username'))){
redirect(base_url()); }
but i have received Error.
Fatal error: Can't use method return value in write context
#7

[eluser]suba[/eluser]
hi,
if(empty($this->session->userdata(‘username’))){
redirect(base_url()); }
but i have received Error.
Fatal error: Can’t use method return value in write context
#8

[eluser]bigtony[/eluser]
Sorry, need slight adjustment...
Code:
$my_variable = $this->session->userdata('my_variable');
if (empty($my_variable)):
    echo 'The my_session variable is empty (or not set).';
endif;
#9

[eluser]wiredesignz[/eluser]
[quote author="bigtony" date="1254231997"]affix: You might want to do your own checking on this, but I think you may run into a problem with:
Code:
if(isset($this->session->userdata('my_var'))
etc...
This is because the userdata function returns 'false' if the variable is not set, which means that isset will return true (because 'false' is a set value).[/quote]

You are both incorrect because you cannot run the isset() function on a function no matter what.
#10

[eluser]Azraf[/eluser]
good reply from all Smile




Theme © iAndrew 2016 - Forum software by © MyBB