From 0b93a8f7cf3e242f474ced004b839e9171e0bfcb Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Wed, 23 Mar 2011 10:47:22 +1300 Subject: [PATCH] API-CHANGE: Allowing non-standard path for session store --- core/Session.php | 24 +++++++++++++++++++++++- tests/SessionTest.php | 7 +++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/Session.php b/core/Session.php index 8bdba0df5..1c9bbc242 100644 --- a/core/Session.php +++ b/core/Session.php @@ -90,6 +90,8 @@ class Session { protected static $cookie_domain; protected static $cookie_path; + + protected static $session_store_path; protected static $cookie_secure = false; @@ -158,6 +160,22 @@ class Session { return (bool) self::$cookie_secure; } + /** + * Set the session store path + * @param string $path Filesystem path to the session store + */ + public static function set_session_store_path($path) { + self::$session_store_path = $path; + } + + /** + * Get the session store path + * @return string + */ + public static function get_session_store_path() { + return self::$session_store_path; + } + /** * Create a new session object, with the given starting data * @@ -430,6 +448,7 @@ class Session { $path = self::get_cookie_path(); $domain = self::get_cookie_domain(); $secure = self::get_cookie_secure(); + $session_path = self::get_session_store_path(); if(!session_id() && !headers_sent()) { if($domain) { @@ -438,6 +457,9 @@ class Session { session_set_cookie_params(self::$timeout, $path, null, $secure /* secure */, true /* httponly */); } + // Allow storing the session in a non standard location + if($session_path) session_save_path($session_path); + // @ is to supress win32 warnings/notices when session wasn't cleaned up properly // There's nothing we can do about this, because it's an operating system function! if($sid) session_id($sid); @@ -497,4 +519,4 @@ class Session { public static function get_timeout() { return self::$timeout; } -} \ No newline at end of file +} diff --git a/tests/SessionTest.php b/tests/SessionTest.php index bd7178991..be53452ab 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -44,4 +44,11 @@ class SessionTest extends SapphireTest { $this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2')); } + + function testNonStandardPath(){ + Session::set_session_store_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session')); + Session::start(); + + $this->assertEquals(Session::get_session_store_path(), ''); + } } \ No newline at end of file