简体   繁体   中英

how can i extend the cookie expiration time in php everytime i i regenerate the session id?

I have a session manager page: sessmgr.php . This page is supposed to validate the user log-in information, set the cookies and keep the session variables alive by updating the cookies expiration time and regenerating the session id by an XML HTTP request at regular intervals till the user logs out. I am able to update the session id but not extend the cookie expiration time.

How to update the cookie expiration time here ??

You should be able to update the expiration time with setcookie like:

 setcookie("Cookiename", $value, NewExpirationTime) 

Check if the Cookiename is exactly the same so that the old Cookie will be overwritten.

用新的时间重写cookie。

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > SESSION_TIMEOUT)) { // SESSION_TIMEOUT is the amount of time you want the session to be.
    session_unset();
    session_destroy();
    header('Location: login.php');
}
$_SESSION['LAST_ACTIVITY'] = time();

Add this to your page. The if-statement checks if the session time has expired and redirects the user to loginpage.php. Otherwise it just updates the session time

Of course you change things to a cookie syntax. Missed that I use sessions and you wanted a cookie.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM