Page 1 of 1

session timeout and redirect

Posted: Mon Apr 21, 2008 1:06 am
by neridaj
Hello,

How do I redirect a user when the session has timed out? It never seems like my sessions timeout e.g., I can always comeback and resume where I left off instead of being redirected when a session has timed out. I know the default time is 20 minutes, but I don't know how to implement a redirect based on that.

Thanks for any help,

Jason

Re: session timeout and redirect

Posted: Mon Apr 21, 2008 3:11 am
by aceconcepts
The default time is 24 minutes and you will be able to check whether a session has expired or has not been set by:

Code: Select all

 
if(!isset(session_id()))
 
//or
 
if(!isset($_SESSION['loggedIn']) || $_SESSION['loggedIn']!=1) //where $_SESSION['loggedIn'] is set to 1 when a user successfully logs in
 

Re: session timeout and redirect

Posted: Tue Apr 22, 2008 1:43 am
by neridaj
I tried that and I'm always immediately redirected when I hit the page.

Code: Select all

session_start();
$_SESSION['valid_user'] = $username;
if(!isset($_SESSION['valid_user']))
    header('Location:http://www.blah.com');
    die("Your session has expired!");
Seems simple enough but...

Thanks,

Jason

Re: session timeout and redirect

Posted: Tue Apr 22, 2008 2:53 am
by aceconcepts
Try outputting your session variable to see if it contains a value.

Re: session timeout and redirect

Posted: Tue Apr 22, 2008 6:09 pm
by neridaj
It does in fact contain the value of $username.