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
session timeout and redirect
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: session timeout and redirect
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
I tried that and I'm always immediately redirected when I hit the page.
Seems simple enough but...
Thanks,
Jason
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!");Thanks,
Jason
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: session timeout and redirect
Try outputting your session variable to see if it contains a value.
Re: session timeout and redirect
It does in fact contain the value of $username.