note 74865 added to ref.session

From: Date: Tue, 01 May 2007 15:45:53 +0000
Subject: note 74865 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-126090@lists.php.net to get a copy of this message
To clear out a possible doubt of other readers which have read this part of "Eric dot Deplagne at nerim dot net" note: -------- In fact, two other variables (at least) play a role in session duration, and will explain that the session might last more than expected. The gc erasing your data is a probabilistic thing. Each time a session is opened, the probability the gc is started is session.gc_probability/session.gc_divisor. session.gc_probability defaults to 1 and session.gc_divisor defaults to 100, which makes a 1% probability. This is to have sessions long enough. I'm unsure about having sessions lasting exactly the time we want them to. -------- The gc erasing of the sessions is NOT a probabilistic thing, they are erased ONLY when they are older than the number of seconds specified in "session.gc_maxlifetime" ini setting. The probabilistic fact is that old sessions will not be erased if the garbage collector is not run frenquently enough, but anyway it is your choice to have a higher or lower "session.gc_probability" on "session.gc_divisor" ratio. So, talking from the server side point of view, a session can last more than the specified amount of time but not less. And if the client respects the cookies duration (in case of cookie-based sessions) those invalid sessions will not last more than expected. You finally might want to add a timestamp inside the session and validate its age through it to radically solve the problem, if necessary. Example: <?php session_start(); if (!isset($_SESSION['generated'])) $_SESSION['generated'] = time(); else { // if the session is not allowed to live more, regenerate it if (time() - $_SESSION['generated'] > ini_get('session.gc_maxlifetime')) $_SESSION = array('generated' => time()); } ?> ---- Server IP: 62.73.196.231 Probable Submitter: 151.75.161.141 ---- Manual Page -- http://www.php.net/manual/en/ref.session.php Edit -- https://master.php.net/note/edit/74865 Del: integrated -- https://master.php.net/note/delete/74865/integrated Del: useless -- https://master.php.net/note/delete/74865/useless Del: bad code -- https://master.php.net/note/delete/74865/bad+code Del: spam -- https://master.php.net/note/delete/74865/spam Del: non-english -- https://master.php.net/note/delete/74865/non-english Del: in docs -- https://master.php.net/note/delete/74865/in+docs Del: other reasons-- https://master.php.net/note/delete/74865 Reject -- https://master.php.net/note/reject/74865 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126090) next »