If you want to control the lifetime of a particular session variable, you will need to roll your own timeout check. The best way to do that is to add a function to your library where you can specify how long a particular variable is valid for. This puts both pieces of information into an array you put in the session. Then, in your common included code, do a loop through that array and unset()
all expired session variables. Make sure the session itself can last as long as the highest value you want to use.
PHP Sessions in and of themselves don't have a hard lifetime value. They have a garbage collector which expires sessions. The setting session.gc_maxlifetime
is the maximum age beyond which the garbage collector will delete the session. Note that this maximum age refers to when it was last accessed, not created.
However, there is also session.gc_probability
and session.gc_divisor
which together tell PHP how often to run the garbage collector. The normal settings mean about 1 in every 100 session starts will run the garbage collector. But this means that if you have a very low volume site, it is possible the garbage collector may not run for many hours. The visible effect of this is that the sessions seem to last way beyond the session.gc_maxlifetime
setting.