PHP: Reset session duration on reboot

This is probably a pretty simple question. I found dozens of these, asking how to generally shorten or extend the session lifetime in PHP. I know how to do this, my PHP script reads like this:

ini_set('session.gc_maxlifetime', 3600); session_set_cookie_params(3600); session_start(); 

This sets my sessions to timeout after 3600 seconds. And this is basically what happens when I start to open a website where I have to log in, I can work with it for exactly one hour, then all the session data is deleted, and I need to log in again.

However, this is not the behavior that I would expect. I want my sessions to disconnect after one hour of inactivity . Therefore, when I first open my site at 10:00, I will do something before 10:45, then it should time out at 11:45, and not at 11:00, as it is now.

Any suggestions to achieve this?

+6
source share
1 answer

Use instead of session_set_cookie_params setcookie

instead

 session_set_cookie_params(3600); session_start(); 

use it and name it on every page of your website.

 $lifetime=3600; session_start(); setcookie(session_name(),session_id(),time()+$lifetime); 

it will update the cookie expiration date for each execution to time()+$lifetime date

+8
source

All Articles