Jump to content

Making a session expire and alert user


AdRock

Recommended Posts

I have a code snippet i've had for months but never used

 

I presume this goes at the top of every page like you would session_start() ?

 

When the session does expire, how do i alert the user they need to log back in again?

define('SESSION_TIMEOUT', 9000); //15 Mins

session_start();
$idletime = time() - isset($_SESSION['time']) ? $_SESSION['time'] : 0;

if($idletime > SESSION_TIMEOUT)
{
     //Reset session
     session_destroy();
     session_start();
}

$_SESSION['time'] = time(); 

Link to comment
https://forums.phpfreaks.com/topic/197801-making-a-session-expire-and-alert-user/
Share on other sites

Right after session_destroy. remove the session_start and put in your alert with a link to the login page. better would be to create an error then redirect to the login page and display the error just as you would for missing form data.

 

 

HTH

Teamatomic

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.