Req #20650 [Opn->Wfx]: Change of Read($sess_id) to ($sess_id, $maxlifetime)
| From: | yohgaki@php.net | Date: | Sat, 31 Mar 2012 04:10:42 +0000 |
| Subject: | Req #20650 [Opn->Wfx]: Change of Read($sess_id) to ($sess_id, $maxlifetime) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169059@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=20650&edit=1
ID: 20650
Updated by: yohgaki@php.net
Reported by: andreas dot birrer at ag dot ch
Summary: Change of Read($sess_id) to ($sess_id, $maxlifetime)
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Session related
PHP Version: 4.2.2
Block user comment: N
Private report: N
New Comment:
You need to lock data, so that the date may not be deleted and/or can stay
consistent.
Previous Comments:
------------------------------------------------------------------------
[2002-11-26 09:43:47] andreas dot birrer at ag dot ch
If I install a user save handler class
e.g. MySqlSessionHandler with methods Read, Write, GC etc.
MySqlSessionHandler::Read($sess_id) is always called before
MySqlSessionHandler::GC($maxlifetime)
This has the problem, that a session is read, which potentially would be garbage collected.
Therefore it would be nice to get the $maxlifetime parameter also in Read e.g. Read($sess_id,
$maxlifetime)
This allows to return an empty session if it has timeouted.
For Clarification here are two Methods GC and Read with $lifetime information
function Read($sess_id, $maxlifetime)
{
// beware of timouted sessions not yet gced
$time_stamp= time();
$removeDate= date("YmdHis", ($time_stamp - $maxlifetime));
$search_query= "SELECT * FROM $_session_table WHERE (session_id = '$sess_id') and
(last_accessed >= $removeDate)";
$result= @ mysql_query($search_query, $_connection);
if(!$result)
{
// No session found - return an empty string
return "";
}
else
{
// Found a session - return the serialized string
$row = mysql_fetch_array($result);
return $row["session_variable"];
}
}
function GC($max_lifetime)
{
global $_connection;
global $_session_table;
$time_stamp= time();
$removeDate= date("YmdHis", ($time_stamp - $max_lifetime));
$delete_query = "DELETE FROM $_session_table WHERE last_accessed < $removeDate";
$result = @mysql_query($delete_query,$_connection);
return true;
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=20650&edit=1