Fixed issue with session_destroy()

This commit is contained in:
Josh Sherman 2011-01-20 22:14:33 -05:00
parent 24770b2e9c
commit 2bb9fd10e4
2 changed files with 32 additions and 14 deletions

View file

@ -108,9 +108,9 @@ class Session extends Object
* Constructor
*
* All of our set up logic for the session in contained here. This object
* is initially instantiated and the event handler is set from pickles.php
* All variables are driven from php.ini and/or the site config. Once
* configured, the session is started automatically.
* is initially instantiated from pickles.php and the session callbacks are
* established here. All variables are driven from php.ini and/or the site
* config. Once configured, the session is started automatically.
*/
public function __construct()
{
@ -130,7 +130,9 @@ class Session extends Object
// Gets a database instance
$this->db = Database::getInstance($this->datasource);
register_shutdown_function('session_write_close');
// Initializes the session
$this->initialize();
session_start();
}
@ -148,6 +150,28 @@ class Session extends Object
session_write_close();
}
/**
* Initializes the Session
*
* This method exists to combat the fact that calling session_destroy()
* also clears out the save handler. Upon destorying a session this method
* is called again so the save handler is all set.
*/
public function initialize()
{
// Sets up the session handler
session_set_save_handler(
array($this, 'open'),
array($this, 'close'),
array($this, 'read'),
array($this, 'write'),
array($this, 'destroy'),
array($this, 'gc')
);
register_shutdown_function('session_write_close');
}
/**
* Opens the Session
*
@ -157,6 +181,8 @@ class Session extends Object
*/
public function open()
{
session_regenerate_id();
return $this->db->open();
}
@ -217,6 +243,8 @@ class Session extends Object
{
$sql = 'DELETE FROM `' . $this->table . '` WHERE id = ?;';
$this->initialize();
return $this->db->execute($sql, array($id));
}