Re: session_save_handler not working within a class?
| From: | Ilja Hehenkamp | Date: | Wed, 08 Nov 2000 18:17:45 +0000 |
| Subject: | Re: session_save_handler not working within a class? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24356@lists.php.net to get a copy of this message | ||
Anyone? I guess this is a bug then...
""Ilja Hehenkamp"" <imhehenkamp@chello.nl> schreef in bericht
news:8ua0bu$r32$1@toye.p.sourceforge.net...
> 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
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>