axit sompura axit sompura -4 years ago 62
PHP Question

How to set expire time in session like as cookie in php?

Hi if i want to use cookie it syntax like below also in this option we can able to set expire time of cookie.


setcookie(name, value, expire, path, domain, secure, httponly);

it is possible to set expire time in session?

Answer Source
//Start our session.

//Expire the session if user is inactive for 30
//minutes or more.
$expireAfter = 30;

//Check to see if our "last action" session
//variable has been set.

    //Figure out how many seconds have passed
    //since the user was last active.
    $secondsInactive = time() - $_SESSION['last_action'];

    //Convert our minutes into seconds.
    $expireAfterSeconds = $expireAfter * 60;

    //Check to see if they have been inactive for too long.
    if($secondsInactive >= $expireAfterSeconds){
        //User has been inactive for too long.
        //Kill their session.


//Assign the current timestamp as the user's
//latest activity
$_SESSION['last_action'] = time();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download