CodeTalk
CodeTalk

Reputation: 3667

Checking for CodeIgniter session_id to not be set

I'm trying to check if its set in my codeigniter application like:

elseif(!isset($this->session->userdata('session_id'))){ ## SESSION data is NOT set
            // load a generic 'issue' occurred view.
        }

but I keep getting this error, is !isset not valid in Codeigniter? How do I go about easily checking this?

Thanks

Upvotes: 0

Views: 90

Answers (2)

tomexsans
tomexsans

Reputation: 4527

You coud also do this ,

elseif($this->session->userdata('session_id') !== false)
{
      // SESSION data is NOT set
      // load a generic 'issue' occurred view.
}

Note: The function returns FALSE (boolean) if the item you are trying to access does not exist.

Upvotes: 0

pktangyue
pktangyue

Reputation: 8524

You must use the code like below:

$id = $this->session->userdata('session_id');
// your other code
elseif(!isset($id)){ 
        // load a generic 'issue' occurred view.
}

The reason you can see here

Upvotes: 1

Related Questions