Jump to content

session expire


kishan

Recommended Posts

HI

iam having a limit of 10 mins for the sessions in my app using..

if (!$_SESSION) {   

session_set_cookie_params(600);

session_start();

}

 

I want to echo a message when the session was timed out how can i know this ?

 

i want ot differentiate the user was visited for the first time and the session was timed out..?

 

Please help Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/126424-session-expire/
Share on other sites

You could just simply redirect them to the login page with a get value such as:

 

header('Location: login.php?timeout=Y');

 

Then on the timeout page you could show a message letting them know what happened.

 

if(isset($_GET['timeout']) && $_GET['timeout'] == "Y"){
echo 'Your session timed out';
}

Link to comment
https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653728
Share on other sites

When you start the session you could do something simple like:

 

$_SESSION['logintime'] = mktime();

 

That will record a timestamp in seconds.

 

Then on another page, simply compare the current time with the older time recorded in the session variable.

 

$now = mktime();
if($now - $_SESSION['logintime'] > 600 ){ 
header('Location: login.php?timeout=Y'); 
}

 

IF 60 seconds have passed, redirect. Probably not the best way to do it but it has done the job for me.

Link to comment
https://forums.phpfreaks.com/topic/126424-session-expire/#findComment-653736
Share on other sites

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.