开发者

Could session_start() in php be messing up my users sessions lengths?

开发者 https://www.devze.com 2023-03-15 10:43 出处:网络
My php.ini file is set开发者_如何学JAVA to expire sessions within 24 hours.But my users complain after being logged out after just 20 minutes or so.

My php.ini file is set开发者_如何学JAVA to expire sessions within 24 hours. But my users complain after being logged out after just 20 minutes or so.

I use session_start at the beginning of every page. Could that be messing things up for me? Or could there be anything else causing this?

Just realized I might be on a shared hosting. And it might have some group settings for garbage collection with sessions. Anyone know how to look into this or set mine to be more specific?

Thanks!


Check phpinfo() to see what the settings really are. PHP has multiple .ini files, and its settings can be overridden in multiple places, so your session session may not be the ones actually in effect. phpinfo's output will show what the "Local" this-is-now-whats-in-effect settings are.

Beyond that, session_start() won't delete a session itself, but it MAY trigger a session garbage collector run based on a few gc_* .ini settings. It's a probabilistic thing, though, and won't happen every time you start a session.

Another possibility is that your session files are going into a system temp directory somewhere, and something external to PHP is cleaning up that directory at 20 minute intervals. So check what the session.save_path setting is and see if anything's cleaning up that location.


ini_set('session.gc_maxlifetime',28800);  #28800 - just an example time - set your own
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);
session_save_path('/path to your sessions folder');
ob_start();
session_start();

You do need to create a session folder first. This works for sure on GoDaddy shared hosting. On VPS you can use this or just update your php.ini file.

0

精彩评论

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

关注公众号