php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19004 Can't register session variable by user-level session storage functions
Submitted: 2002-08-20 18:41 UTC Modified: 2002-09-29 20:01 UTC
From: frank at orite dot com Assigned:
Status: Closed Package: Session related
PHP Version: 4.2.2 OS: Windows, IIS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: frank at orite dot com
New email:
PHP Version: OS:

 

 [2002-08-20 18:41 UTC] frank at orite dot com
register_globals = Off

[Session]
session.save_handler = user
session.save_path = /tmp
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_maxlifetime = 1440
session.referer_check =
session.entropy_length = 0
session.entropy_file =
;session.entropy_length = 16
;session.entropy_file = /dev/urandom
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 1
url_rewriter.tags =
"a=href,area=href,frame=src,input=src,form=fakeentry"

I'm trying to use my own session handle functions, which basically stores information into mysql database. Since I did turn on register_globals as recommended, I have to use $_SESSION["foo"]="bar" to register a session variable. The session starts and reads soundly, but it never registers the variable in this way, seems the write function hasn't been called when we declare $_SESSION["foo"]="bar".

However if we force a session_register(), the variable can be written and read on the following pages by accessing the variable $_SESSION.

Note: when I'm on session.save_handler = files, $_SESSION["foo"]="bar" will simply register the varible to the session file stored.

Here's a paste of my handler functions:
function myopen ($mys_table, $mys_name) {
	global $mysession;
	$mysession['table'] = $mys_table;
	$mysession['name'] = $mys_name;
	return true;
}

function myclose() {
	global $mysession;
	unset($mysession);
	return true;
}

function myread ($id) {
	global $mysession;
	$sql="SELECT data FROM ".$mysession['table']." WHERE sid='".$id."'";
	$result=@mysql_query($sql);
	$data=@mysql_result($result,0,"data");
	if (strlen($data)>0) {
		$la=time();
		$sql="UPDATE ".$mysession['table']."SET lastact='".$la."' WHERE sid='".$id."'";
	}
	return $data;
}

function mywrite ($id, $data) {
	global $mysession;
	echo "write".$data."<br>";
//destory history data before write
	$dsql="DELETE FROM ".$mysession['table']." WHERE sid='".$id."'";
	@mysql_query($dsql);
//write new data
	$la=time();
	$wsql="INSERT INTO ".$mysession['table']." (sid,data,lastact) VALUES ('".$id."','".addslashes($data)."','".$la."')";
	@mysql_query($wsql);
	return true;
}

function mydestroy ($id) {
	global $mysession;
	$sql="DELETE FROM ".$mysession['table']." WHERE sid='".$id."'";
	$result=@mysql_query($sql);
	return true;
}

function mygc ($maxlifetime) {
	global $mysession;
	$limitime=time()-$maxlifetime;
	$sql="DELETE FROM ".$mysession['table']." WHERE lastact<'".$limitime."'";
	@mysql_query($sql);
	return true;
}

//save_path is the SQL table name
session_save_path("mysession");

//customize the session handler
session_set_save_handler ("myopen", "myclose", "myread", "mywrite", "mydestroy", "mygc");

//session start
session_start();

Has anyone got a solution to this problem, I mean if there's an alternative way of coding the handle function for this issue. Or this is simply a php bug?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-20 21:35 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip
 [2002-08-20 21:35 UTC] sniper@php.net
And btw: We do NOT recommend to turn register_globals=on...

 [2002-08-21 00:57 UTC] frank at orite dot com
sorry, that was a typo, I actually mean I didn't. From the abstract of my settings listed that's Off indeed.
 [2002-08-21 01:28 UTC] frank at orite dot com
I've tried http://snaps.php.net/win32/php4-win32-latest.zip just now, this problem persists.
 [2002-09-29 11:16 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-09-29 19:01 UTC] frank at orite dot com
Acctually this problem has been fix under php 4.2.3, I'm using my functions now with no problem.
Thank you!
 [2002-09-29 19:01 UTC] frank at orite dot com
Acctually this problem has been fix under php 4.2.3, I'm using my functions now with no problem.
Thank you!
 [2002-09-29 20:01 UTC] sniper@php.net
fixed -> closed.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC