JustinK101 Posted June 6, 2008 Share Posted June 6, 2008 What is the lifetime of a standard php session created by simply session_start(); and $_SESSION = "test123"? From my understanding sessions live until the user closes their browser. Assuming the user doesn't close their browser but leaves their computer completely idle for say 12 hours will the session still persist? What about the server clearing temp automatically? Basically I need sessions to always exist until the user closes their browser or a minimum of 8 hours. Thanks. Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/ Share on other sites More sharing options...
RMcLeod Posted June 6, 2008 Share Posted June 6, 2008 Try this <?php ini_set('session.cookie_lifetime', 0); ini_set('session.gc_maxlifetime', 28800); // Alter as required 28800 is 8 hours (value is in seconds) try 86400 for 24 hrs ?> Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/#findComment-558958 Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 Do I call this on every page before session_start() or after? Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/#findComment-558959 Share on other sites More sharing options...
RMcLeod Posted June 6, 2008 Share Posted June 6, 2008 The best way would be to set these in your php.ini file directly if you have access to it. However this will then be system wide and any other sites on the server will have the same session length, hopefully you see the security risk of having such long session times. Otherwise use the code above as the first two lines of your PHP script, before anything else. Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/#findComment-558961 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2008 Share Posted June 6, 2008 If you are on a shared host and your session.save_path setting is the default shared folder, the shortest session.gc_maxlifetime of all the scripts running on the host will win and remove any of your session data files (ending those sessions) that are older than the session.gc_maxlifetime value in effect for a session_start() that triggers garbage collection. In this case, you would also need to also set the session.save_path to be a folder within your hosting account's directory structure. Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/#findComment-559215 Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 So if I don't set any maxlifetime, the default behavior is sessions are valid until they are unset or the user closes their browser right? There is a no time restriction correct? Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/#findComment-559324 Share on other sites More sharing options...
JustinK101 Posted June 7, 2008 Author Share Posted June 7, 2008 bump, anybody know the question I asked above? Thanks. Link to comment https://forums.phpfreaks.com/topic/108952-session-lifetime/#findComment-559565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.