session_save_handler not working within a class?
| From: | Ilja Hehenkamp | Date: | Tue, 07 Nov 2000 22:41:47 +0000 |
| Subject: | session_save_handler not working within a class? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24216@lists.php.net to get a copy of this message | ||
Hi,
I searched around but couldn't find an answer on this:
I've made a session class which uses the session_save_handler for handling
the sessions through a MySQL DB, but it seems it has a problem with
accessing class-methods...
// Start code:
<?php
class Session
{ var $db;
var $tpl;
var $table;
var $userID;
var $tplVars;
function Session($db, $table, $userID, $tplVars = array(), $tpl =
"_login.tpl")
{ $this->db = $db;
$this->tpl = $tpl;
$this->table = $table;
$this->tplVars = $tplVars;
$this->userid = $userID;
if(!empty($userID))
$this->startSession($this->userID);
else
$this->getLogin();
}
function startSession($userID)
{ setcookie ("FeyenoordForever[userID]", $userID, time() + 3600);
session_set_save_handler("open", "close", "read", "write",
"destroy",
"gc");
session_start();
session_register("userID");
$HTTP_SESSION_VARS[userID] = $this->userID;
}
function loggedIn()
{
}
function login()
{
}
function getLogin()
{ $tpl = new Template("./Templates/$this->tpl");
$tpl->assign($this->tplVars);
$tpl->parse("Main");
$tpl->out("Main");
}
function open($save_path, $session_name)
{ return(true);
}
function close()
{ return(true);
}
function read($id)
{ $query = "SELECT sessionData FROM $this->table WHERE sessionID = $id";
if($result = $this->db->execQuery($query))
return $this->db->getFirst($result);
else
return("");
}
function write($id, $sess_data)
{ $query = "REPLACE INTO $this->table (sessionID, sessionData, userID,
lastAction) VALUES ('$id', '$sess_data', $this->userID,
UNIX_TIMESTAMP())";
return($this->db->execQuery($query));
}
function destroy($id)
{ $query = "DELETE FROM $this->table WHERE sessionID = $id";
return($this->db->execQuery($query));
}
function gc($maxlifetime)
{ $old = time() - $maxlifetime;
$query = "DELETE FROM $this->table WHERE lastAction < $old";
return($result = $this->db->execQuery($query));
}
}
?>
// end code
I've tried session_set_save_handler("\$this->open", "\$this->close",
"\$this->read", "\$this->write", "\$this->destroy",
"\$this->gc"); with no
luck also...
Anyone knows how to fix this?
Thanks in advance,
Regards,
Ilja Hehenkamp