CodeIgniter Forums
Check session exit ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Check session exit ? (/showthread.php?tid=52228)



Check session exit ? - El Forum - 06-02-2012

[eluser]Hamed[/eluser]
Hello,
How can I check session exit for example I use isset() in normal php now I want to check $this->session->userdata('uid') exit or set.


Check session exit ? - El Forum - 06-02-2012

[eluser]Oscar Dias[/eluser]
When you exit the session you can unset the userdata
Code:
$this->session->unset_userdata('uid');
Then when you check $this->session->userdata('uid') it will return false. If it returns the uid than the user did not exit the session.



Check session exit ? - El Forum - 06-02-2012

[eluser]Hamed[/eluser]
Then when there is no session for uid $this->session->userdata(‘uid’) return false//?


Check session exit ? - El Forum - 06-02-2012

[eluser]dnc[/eluser]
Just Like Oscar Dias said when you unset the session it should return false. If you want to make sure than just like was said in PHP:

Code:
if(!isset($this->session->userdata('uid'))) {

//do whatever you need to do. The session['uid'] is not set

}


By the way your still working with "normal" PHP. Just got an awesome framework to kickstat your work with.




Check session exit ? - El Forum - 06-03-2012

[eluser]dnc[/eluser]
Actually I told you wrong on this. You will have to check it like:


Code:
if(!$this->session->userdata('uid'))) {

//do whatever you need to do. The session['uid'] is not set

}