How to make a PHP session expire when you close your browser OR some lengthy time

My php session expires when the user closes the browser, but I noticed that if I keep my browser open for a long period of time (e.g. 24 hours), the session is still saved.

Is there a way I can end these sessions, either when the browser is closed, or when it takes some time?

+3
source share
1 answer

The solution may be to install the data through ini_set('session.gc_maxlifetime', <lifetime in seconds>);Of course, if you can change the configuration through PHP. Otherwise, you will need to set the correct values ​​to php.ini:

ini_set(‘session.gc_maxlifetime’,30);
ini_set(‘session.gc_probability’,1);
ini_set(‘session.gc_divisor’,1);

cookie :

$expire=24*60*60;
session_set_cookie_params($expire);
session_start();
+6

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