Set session end time

How to set session expiration time to 10 minutes for my entire site? I can not use php.ini as a shared hosting.

Can the global method be used?

+4
source share
2 answers

I do not think so.

You can save the timestamp of the last update of your site in the session and compare it with the current time at the next reboot.

 if(isset($_SESSION['expiretime'])) { if($_SESSION['expiretime'] < time()) { //logged out } else { $_SESSION['expiretime'] = time() + 600; } } //maybe add some login procedures and than execute the following line $_SESSION['expiretime'] = time() + 600; 
+6
source

A really complex subject, you can use the following:

 session_set_cookie_params(600); 

The witch actually sets the cookie, so the cookie expires after 10 minutes when the user makes a request to the browser without sending the phpsessid cookie, so php will issue a new session. The problem is that it does not cancel the previous session, so the previous session will still be valid.

session_set_cookie_params

+2
source

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


All Articles