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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.