Here is the modified session_write function, the
original crashes because of the test ran to check if
the session already exists.
Pear error handling overrides your test, so when you
try to do an insert on a session_id which already
exists PEAR crashes saying "Duplicate record"
function pear_session_write($session_id, $data)
{
/*
* Writes serialized session data to the database.
Where the session
* already exists, it is updated.
* Returns true on success, false on error.
*
* Apache users: note that this function is not
called until after the
* output stream has been closed. DO NOT print
anything in this
* function, as not only will you not see it, but
you may prevent
* the session data being updated. You have been
warned.
*/
$expires = time() + get_cfg_var
("session.gc_maxlifetime");
$sql = "SELECT session_id FROM " .
PEAR_SESSION_TABLE . " WHERE session_id='$session_id'";
$rs = $GLOBALS['pear_session_db']->query($sql);
if ($rs->numRows() != 0) { // means the session
already exists
$sql = "UPDATE " . PEAR_SESSION_TABLE . " SET
expires = $expires, data = '"
. addslashes($data) . "' WHERE session_id
= '" . addslashes($session_id)
. "'";
$rs = $GLOBALS['pear_session_db']->query($sql);
} else {
$sql = "INSERT INTO " .
PEAR_SESSION_TABLE . "(session_id, expires, data) "
. "VALUES('" . addslashes($session_id) . "',
$expires, '" . addslashes($data)
. "')";
$rs = $GLOBALS['pear_session_db']->query($sql);
} // if
/* $rs = ;
if (DB::isError($GLOBALS['pear_session_db']->query
($sql))) // probably a duplicate error: update
existing value
{
$sql = "UPDATE " . PEAR_SESSION_TABLE . " SET
expires = $expires, data = '"
. addslashes($data) . "' WHERE session_id
= '" . addslashes($session_id)
. "'";
$rs = $GLOBALS['pear_session_db']->query($sql);
}*/
return !(DB::isError($rs));
}