How long php sessions are stored in server?

做~自己de王妃 提交于 2020-04-10 06:30:50

问题


I'm wondering how long php sessions are stored in server memory.What if user logs in (sets session variables in server) and he keeps his browser open for a long time suppose 30 days and he reloads the page on the 31st day? Can browser access session variables(browser still has session cookie)?


回答1:


Default php.ini sets the session expiration time to 30 minutes.

Check out these settings: session.gc_maxlifetime and session.cookie_lifetime

As long as the browser have the cookie stored, it doesn't matter if it is closed or is open.

If you want to store the session for lets say 30 days, you can add:

ini_set('session.gc_maxlifetime', 30*24*60*60);
ini_set('session.cookie_lifetime', 30*24*60*60);



回答2:


Normally you would code as part of your session handling code a function for expiring sessions after some time has elapsed, so in that case it would't matter how long they left there browser open




回答3:


I think this depends on what you have set in php.ini http://php.net/manual/en/function.session-set-cookie-params.php



来源:https://stackoverflow.com/questions/25999552/how-long-php-sessions-are-stored-in-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!