开发者

How to have PHP session expire upon browser close OR some extended duration of time

开发者 https://www.devze.com 2023-01-17 02:33 出处:网络
My php session is set to expire when user closes the browser but I noticed that if I leave my browser open for an extended period of time (24+ hours for example) the se开发者_高级运维ssion still persi

My php session is set to expire when user closes the browser but I noticed that if I leave my browser open for an extended period of time (24+ hours for example) the se开发者_高级运维ssion still persists.

Is there a way that I can have these sessions expire either when the browser is closed or when some extended period of time has transpired?


The solution might be to set data via ini_set('session.gc_maxlifetime', <lifetime in seconds>); Of course if it's possible to change config via PHP. Otherwise you wil need to set proper values in your php.ini:

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

The other approach is setting validity of session cookie by:

$expire=24*60*60;
session_set_cookie_params($expire);
session_start();
0

精彩评论

暂无评论...
验证码 换一张
取 消