Prodigal Son Posted December 11, 2008 Share Posted December 11, 2008 I'm trying to extend my php sesson timeout. From googling I am using this: $timeout = ini_set("session.gc_maxlifetime", 3600); That should set the timeout to 1 hour right? However when I echo the timeout it says the timeout is 24 minutes. Any ideas what is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2008 Share Posted December 11, 2008 Form the ini_set() section in the php manual - Return Values Returns the old value on success, FALSE on failure. Please read the relevant section in the php manual, especially when something does not work. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-712782 Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 ini_set("session.gc_maxlifetime", 3600); This assumes you are allowed to use ini_set. and the $timeout you were setting it to I do not think was accurate. To check use ini_get and see. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-712787 Share on other sites More sharing options...
Prodigal Son Posted December 11, 2008 Author Share Posted December 11, 2008 ini_set("session.gc_maxlifetime", 3600); This assumes you are allowed to use ini_set. and the $timeout you were setting it to I do not think was accurate. To check use ini_get and see. Used ini_get and it printed out 3600. But the session still doesn't last an hour. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-712973 Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 ini_set("session.gc_maxlifetime", 3600); This assumes you are allowed to use ini_set. and the $timeout you were setting it to I do not think was accurate. To check use ini_get and see. Used ini_get and it printed out 3600. But the session still doesn't last an hour. I would define that in the .htaccess file instead of ini_set to be honest. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-712979 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2008 Share Posted December 11, 2008 You must set that value before every session_start() statement. Post your actual code? Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-712980 Share on other sites More sharing options...
Prodigal Son Posted December 11, 2008 Author Share Posted December 11, 2008 You must set that value before every session_start() statement. Post your actual code? Ah, that explains it. Apparently I've been placing that right under session_start thinking that is always the first line. Tested it and its working now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-713059 Share on other sites More sharing options...
Prodigal Son Posted December 17, 2008 Author Share Posted December 17, 2008 Hmm, I noticed something weird happening. After I use ini_set to change the session timeout, it makes the timeouts random it seems. For example, before when I had my default session timeout at 24 minutes, everytime the session would expire at that time. But now it can expire at random times, sometimes it can last up to half an hour or so, sometimes the session dies in even 1-2 minutes. I have googled this and found someone had the same problem, but never got an answer. I tested with almost a blank page to make sure it wasn't some other code interfering, but the same still happens. Anyone have a similar experience? Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-718120 Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2008 Share Posted December 17, 2008 Are you on shared hosting or a dedicated server? Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-718164 Share on other sites More sharing options...
Prodigal Son Posted December 17, 2008 Author Share Posted December 17, 2008 Are you on shared hosting or a dedicated server? Shared. Could that be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-718168 Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 Are you on shared hosting or a dedicated server? Shared. Could that be the problem? Very well. Shared hosting is very unsecure and chances are you do not have alot of permissions on it. Thus you cannot set your own timeouts cause you cannot access the php.ini and probably cannot use the ini_set feature either. I bet the .htaccess version is also blocked for "Security" reasons by your host. Glad I have a dedicated server =) Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-718188 Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2008 Share Posted December 17, 2008 When the session data files are stored in the default folder, the shortest session.gc_maxlifetime setting of all the scripts running on that server is what wins. Someone probably has set it to a short value in order to cause sessions to end to log someone out instead of correctly coding their application to handle the log out in the application. You should set the session.save_path to be to a private folder that is within your account's folder tree. The best place for a folder to hold the session data files is in a folder that is outside of your document root folder (closer to the root of the disk). If you are not able to create a folder at that point in the folder tree, you will need to create a folder inside your document root folder and you will need to add a .htaccess file in it to prevent access to all http requests so that someone that guesses the folder name cannot attempt to access the session data files. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-718196 Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 PFMaBiSmAd be nice if u gave a full description on ur findings for us all. I do understand your explanation but a written example be nice for me to print out for reference. Thank u for pointing out this cheers m8. Only if u got time once agin thank you nice info. Quote Link to comment https://forums.phpfreaks.com/topic/136551-extending-php-session-timeout/#findComment-718217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.