Detect if Session expired
Posted: Wed Jul 28, 2004 4:12 am
I have a simple login script just for testing purposes.
I have this at the top of all my protected pages
Basically, when the user logs in $_SESSION['auth'] is set to true index.php is the login page they are redirected to if they aren't logged in and try to access a protected page.
Sessions timeout out after a certain perios of time set in the php.ini. What i want to do is detect if the session has timed out, so if it has, when the user is redirected back to the login page, they are also presented with a message along the lines of "For security reasons, you were automatically logged out".
Is this possible?
I am guessing i can't detect if the session has expired directly, but i could start a timer to detect the length of inactivity!?
Some pseudo code or point me in the direction fo the function i may need will do.
Thanks
Mark
I have this at the top of all my protected pages
Code: Select all
session_start(); // Start/Resume session
if ( !$_SESSION['auth'] ) {
header("Location: /index.php");
}Sessions timeout out after a certain perios of time set in the php.ini. What i want to do is detect if the session has timed out, so if it has, when the user is redirected back to the login page, they are also presented with a message along the lines of "For security reasons, you were automatically logged out".
Is this possible?
I am guessing i can't detect if the session has expired directly, but i could start a timer to detect the length of inactivity!?
Some pseudo code or point me in the direction fo the function i may need will do.
Thanks
Mark