Longer PHP Sessions

Extending session length for PHP on a hosted account is not as easy as it seems at first.

I had problems with the "session.gc_maxlifetime" settings (in both .htaccess and using ini_set() in the scripts themselves). I believe the problem is that it\'s all fine and good to tell your scripts how long a session should exist. But, garbage collection (deletion of unused session files) is common to all on the server - i.e. all the session files are stored together, with no differentiation between the actual web sites that created the sessions. Thus, unless all of your peers on your web host use the same gc_maxlifetime, your session files will disappear! (i.e. do something else!)

My solution was to use a custom session handler. I used the mysql session handler that was posted by a user on this page of the PHP.net manual:

http://ca2.php.net/manual/en/function.session-set-save-handler.php

There are other benefits since it\'s all customizable.
Related Scribbles:


ID: 369
Author:
leonard
Date Updated:
2003-12-07 16:54:23
Date Created:
2003-12-07 16:51:30

Edit

Comments?
 >> Leonard Chan's Homepage  >> Scribble Web  >> Longer PHP Sessions
leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.