Jump to content

session expire time


woodplease

Recommended Posts

how can i set a session to expire after a set amount of time, say 1 hour.

 

i'm using the following code to create my session, but i dont know what i need to add to make it expire

 

$_SESSION['pageviewsid'.$id] = $new;

 

 

 

$new is the result from a calculation and $id is the page id from the URL using $_GET

 

Link to comment
Share on other sites

when the session is started, you can set a session variable with the current unix timecode... then check to see if it is more than 1hour past the sign in time...

session_start();

//log in etc etc
//when login authenticated, add this line
$_SESSION['sessionStart'] = time();

 

then in your script where it checks the user is logged in each time a page is viewed, add a line like

if ((time() - $_SESSION['sessionStart']) > 60*60)
{
session_destroy();
exit("Session expired");
}

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.