API-CHANGE: Allowing non-standard path for session store

This commit is contained in:
Julian Seidenberg 2011-03-23 10:47:22 +13:00 committed by Ingo Schommer
parent 5efdc60029
commit 0b93a8f7cf
2 changed files with 30 additions and 1 deletions

View File

@ -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;
}
}
}

View File

@ -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(), '');
}
}