![]() |
Determining whether a session expired - 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: Determining whether a session expired (/showthread.php?tid=19272) |
Determining whether a session expired - El Forum - 06-02-2009 [eluser]mrmeyers99[/eluser] On my site I'm using the PHP session library to store the user sessions. If a user tries to access a page when they aren't logged in, I need to redirect them. How can I tell if their session expired vs if they just try to get to that page without being logged in? Determining whether a session expired - El Forum - 06-03-2009 [eluser]TheFuzzy0ne[/eluser] Assuming your referring to native PHP sessions, when the user logs you'll normally set some kind of variable to indicate that a user has logged in: Code: $_SESSION['logged_in'] = TRUE; All you need to do is check that isset($_SESSION['logged_in']), and the job's a good'en. Determining whether a session expired - El Forum - 06-03-2009 [eluser]mrmeyers99[/eluser] but once the session expires $this->session->userdata('logged_in') will return the empty string. Determining whether a session expired - El Forum - 06-03-2009 [eluser]Dam1an[/eluser] it returns false, so if you do Code: if($this->session->userdata('logged_in')) and it returns false, its either cause they're not logged in or its timed out, and in both cases, you want the same to happen ![]() Determining whether a session expired - El Forum - 06-03-2009 [eluser]mrmeyers99[/eluser] Right but I want to give them a different message depending on if their session expired vs. if they just tried to access the page without logging in. (i.e. "Your session has expired" vs. "You must log in to see this page") Determining whether a session expired - El Forum - 06-04-2009 [eluser]mrmeyers99[/eluser] Plenty of other sites do this, so it must be possible. If the session expires after 10 minutes of inactivity there has to be a way to tell between that and someone who hasn't logged in right? Determining whether a session expired - El Forum - 06-05-2009 [eluser]TheFuzzy0ne[/eluser] I think it's usually done using two cookies. One expires normally, but the other lasts much longer (I like to call it the "remember me" cookie). |