Authored by ziy

修改Session

1、自定义域
2、自定义Session Name
... ... @@ -47,7 +47,7 @@ class CacheSession extends Root implements SessionHandlerInterface
/**
* 初始化
*/
public function __construct()
public function __construct($sessionName = null, $domain = null)
{
session_set_save_handler(
array(&$this, "open"),
... ... @@ -60,8 +60,14 @@ class CacheSession extends Root implements SessionHandlerInterface
if (version_compare(phpversion(), '5.4.0', '>=')) {
register_shutdown_function('session_write_close');
}
if ($sessionName != null && is_string($sessionName) && strlen($sessionName) > 1) {
ini_set("session.name", $sessionName);
}
ini_set("session.use_cookies", 1);
ini_set("session.cookie_domain", ".yohobuy.com");
ini_set('use_only_cookies', 0);
if ($domain != null) {
ini_set("session.cookie_domain", '.' . $domain);
}
ini_set('session.cookie_path', '/');
ini_set('session.gc_maxlifetime', $this->gcMaxLifeTime);
}
... ... @@ -145,7 +151,6 @@ class CacheSession extends Root implements SessionHandlerInterface
public function write($sessionID, $sessionData)
{
$return = $this->cache()->set($this->sessionPrefix . $sessionID, $sessionData, $this->gcMaxLifeTime);
var_dump($return);exit;
return $return;
}
... ...
... ... @@ -22,10 +22,10 @@ class Session
* @param $namespace
* @return SessionNamespace
*/
static public function start($namespace = 'session_default')
static public function start($namespace = 'session_default', $sessionName = '_QIN')
{
if (self::isSessionStarted() == false || self::$_session == null) {
self::$_session = new CacheSession();
self::$_session = new CacheSession($sessionName);
session_start();
}
return new SessionNamespace ($namespace);
... ...