Commit 3e255e54 authored by Taddeus Kroes's avatar Taddeus Kroes

Session::destroy() now also removes session data from cookie

parent 5614a4de
...@@ -92,11 +92,23 @@ class Session implements Singleton { ...@@ -92,11 +92,23 @@ class Session implements Singleton {
$_SESSION = array(); $_SESSION = array();
} }
function destroy($clear=false) { function destroy($clear=true) {
// Delete session
session_destroy();
// Clear session variables
if ($clear) if ($clear)
$this->clear(); $this->clear();
session_destroy(); // Delete session cookie
if (ini_get('session.use_cookies')) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params['path'],
$params['domain'], $params['secure'], $params['httponly']);
}
// Delete reference to instance so that the next getInstance() call
// will start a new session
self::$instance = null; self::$instance = null;
} }
} }
......
...@@ -72,9 +72,6 @@ class SessionTest extends SingletonTestCase { ...@@ -72,9 +72,6 @@ class SessionTest extends SingletonTestCase {
$old_id = session_id(); $old_id = session_id();
$this->session->regenerateId(); $this->session->regenerateId();
$this->assertNotEquals($old_id, session_id()); $this->assertNotEquals($old_id, session_id());
// Disable output buffering to show progress on other tests
@ob_end_flush();
} }
function testClear() { function testClear() {
...@@ -83,17 +80,12 @@ class SessionTest extends SingletonTestCase { ...@@ -83,17 +80,12 @@ class SessionTest extends SingletonTestCase {
$this->assertEmpty($_SESSION); $this->assertEmpty($_SESSION);
} }
function testDestroySimple() {
$this->session->destroy();
$this->assertEquals('', session_id());
}
/** /**
* @depends testClear * @depends testClear
*/ */
function testDestroyClear() { function testDestroyClear() {
$_SESSION['foo'] = 'bar'; $_SESSION['foo'] = 'bar';
$this->session->destroy(true); $this->session->destroy();
$this->assertEmpty($_SESSION); $this->assertEmpty($_SESSION);
$this->assertEquals('', session_id()); $this->assertEquals('', session_id());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment