How can I extend the cookie expiration time in php every time I update the session id?

I have a session manager page: sessmgr.php. This page should check the user's login information, set cookies and keep the session variables alive, updating the cookie expiration time and restoring the session ID with an HTTP HTTP request at regular intervals until the user logs out. I can update the session ID but not extend the cookie expiration time.

How to update cookie expiration time here?

+6
source share
3 answers

You can update the expiration time of setcookie , for example:

 setcookie("Cookiename", $value, NewExpirationTime) 

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

+9
source

just rewrite the cookie with a new time.

-1
source
 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 has expired and redirects the user to loginpage.php. Otherwise, it just updates the session time

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

-1
source

Source: https://habr.com/ru/post/959163/


All Articles