php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38241 session_set_save_handler() can't work well
Submitted: 2006-07-28 09:26 UTC Modified: 2006-07-30 10:19 UTC
From: qw_kerry at yahoo dot com dot cn Assigned:
Status: Not a bug Package: Session related
PHP Version: 5CVS-2006-07-28 (snap) OS: Windows 2003 SP1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: qw_kerry at yahoo dot com dot cn
New email:
PHP Version: OS:

 

 [2006-07-28 09:26 UTC] qw_kerry at yahoo dot com dot cn
Description:
------------
I use session_set_save_handler() to define my own session handler. It can read session values, but can't write them. But the function work well when I run my script on php 5.1.4. 

Session is stored in database in my script. When I store session in files, session is written well.

Reproduce code:
---------------
The functions except for DBSessionWrite are omitted. PDO_MYSQL is used.

function DBSessionWrite($aKey,$aVal)
{
	global $_sessiondb,$_sessiontable;
	$sql = "SELECT lastupdated FROM ".$_sessiontable." WHERE sessionid=?";
	$stmt = $_sessiondb->prepare($sql);
	$stmt->execute($aKey);
	if($stmt->fetchColumn()) {
		$sql = "UPDATE ".$_sessiontable." SET datavalue=?, lastupdated=? WHERE sessionid=?";
		$stmt = $_sessiondb->prepare($sql);
		$stmt->execute(array($aVal,time(),$aKey));
	}
	else {
		$sql = "INSERT INTO ".$_sessiontable." VALUES (?,?,?)";
		$stmt = $_sessiondb->prepare($sql);
		$stmt->execute(array($aKey,time(),$aVal));
	}
	return $stmt->rowCount();
}


session_set_save_handler("DBSessionOpen", "DBSessionClose", "DBSessionRead", "DBSessionWrite", "DBSessionDestroy", "DBSessionGC");
session_start();

$session_idencode = md5($_SERVER["REMOTE_ADDR"]);
if($session_idencode != $_SESSION['idencode']) {
	session_regenerate_id(true);
	$_SESSION['idencode'] = $session_idencode;
}

Expected result:
----------------
One new row should appear in the session table.

Actual result:
--------------
No new row appear.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-28 09:31 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-07-29 09:04 UTC] qw_kerry at yahoo dot com dot cn
Description:
------------
I use session_set_save_handler() to define my own session handler. It can read session values, but can't write them. But the function work well when I run my script on php 5.1.4. 

Environment
OS: Windows 2003 SP1
Apache: 2.2.2
Mysql: 5.0.22

Reproduce code:
---------------
You can find my script in the following url.
http://www.30t.net/bug/session.txt

The session table structure is defined as

CREATE TABLE `session` (
  sessionid char(28) character set latin1 collate latin1_general_ci NOT NULL,
  lastupdated int(11) NOT NULL,
  datavalue varchar(1000) character set latin1 collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (sessionid)
) ENGINE=MEMORY DEFAULT CHARSET=utf8;



Expected result:
----------------
One new row should appear in the session table.

Actual result:
--------------
Fatal error: Call to a member function prepare() on a non-object in E:\sumly2007\test.php on line 6
 [2006-07-30 10:19 UTC] tony2001@php.net
Expected behaviour.
Function DBSessionWrite() is called when PDO object is already destroyed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 08:01:33 2024 UTC