#19004 [NEW]: Can't register session variable by user-level session storage functions
| From: | frank at orite dot com | Date: | Tue, 20 Aug 2002 22:41:14 +0000 |
| Subject: | #19004 [NEW]: Can't register session variable by user-level session storage functions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-17363@lists.php.net to get a copy of this message | ||
From: frank@orite.com
Operating system: Windows, IIS
PHP version: 4.2.2
PHP Bug Type: Session related
Bug description: Can't register session variable by user-level session storage functions
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?
--
Edit bug report at http://bugs.php.net/?id=19004&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=19004&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=19004&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=19004&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=19004&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=19004&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=19004&r=support
Expected behavior: http://bugs.php.net/fix.php?id=19004&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=19004&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=19004&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=19004&r=globals