Jump to content

[SOLVED] Session Cookies not lasting very long


ArizonaJohn

Recommended Posts

Hi,

 

I'm using session cookies and they work great at first.  But if I have a page pulled up for about 45 minutes, the session cookies seem to die, even if I don't open up any other websites.

 

Are there measures that I could take to make my session cookies last longer?

 

Thanks,

 

John

 

The session cookie will exist as long as at least one instance or tab of the browser is kept open. It is more likely that the session data file is being deleted on the server.

 

On busy web servers, the session garbage collection runs frequently and deletes any session data files that have a last access time older than the session garbage collection maximum lifetime.

 

Are you on a shared web server?

In order to set a longer session.gc_maxlifetime, you will first need to set session.save_path to be to a private folder within your account's folder tree. This is so that when garbage collection runs, it only operates on your session data files and uses your session.gc_maxlifetime setting.

 

If possible, set session.save_path to be to a folder that is outside of your document root folder (closer to the disk root folder.) If that option is not available you will need to set it to a folder within your document root folder. In this case, you should also put a .htaccess file in the folder that prevents all http/https access to the files in the folder.

 

Both session.save_path and session.gc_maxlifetime must be set before every session_start() statement. It is best to put these settings into a .htaccess file (when php is running as an Apache module) or in a local php.ini file (when php is running as a CGI application.) If neither of those options are available you can set them in your script but they must be set before every session_start() statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.