Authored by ziy

修改Session

1、自定义域
2、自定义Session Name
@@ -47,7 +47,7 @@ class CacheSession extends Root implements SessionHandlerInterface @@ -47,7 +47,7 @@ class CacheSession extends Root implements SessionHandlerInterface
47 /** 47 /**
48 * 初始化 48 * 初始化
49 */ 49 */
50 - public function __construct() 50 + public function __construct($sessionName = null, $domain = null)
51 { 51 {
52 session_set_save_handler( 52 session_set_save_handler(
53 array(&$this, "open"), 53 array(&$this, "open"),
@@ -60,8 +60,14 @@ class CacheSession extends Root implements SessionHandlerInterface @@ -60,8 +60,14 @@ class CacheSession extends Root implements SessionHandlerInterface
60 if (version_compare(phpversion(), '5.4.0', '>=')) { 60 if (version_compare(phpversion(), '5.4.0', '>=')) {
61 register_shutdown_function('session_write_close'); 61 register_shutdown_function('session_write_close');
62 } 62 }
  63 + if ($sessionName != null && is_string($sessionName) && strlen($sessionName) > 1) {
  64 + ini_set("session.name", $sessionName);
  65 + }
63 ini_set("session.use_cookies", 1); 66 ini_set("session.use_cookies", 1);
64 - ini_set("session.cookie_domain", ".yohobuy.com"); 67 + ini_set('use_only_cookies', 0);
  68 + if ($domain != null) {
  69 + ini_set("session.cookie_domain", '.' . $domain);
  70 + }
65 ini_set('session.cookie_path', '/'); 71 ini_set('session.cookie_path', '/');
66 ini_set('session.gc_maxlifetime', $this->gcMaxLifeTime); 72 ini_set('session.gc_maxlifetime', $this->gcMaxLifeTime);
67 } 73 }
@@ -145,7 +151,6 @@ class CacheSession extends Root implements SessionHandlerInterface @@ -145,7 +151,6 @@ class CacheSession extends Root implements SessionHandlerInterface
145 public function write($sessionID, $sessionData) 151 public function write($sessionID, $sessionData)
146 { 152 {
147 $return = $this->cache()->set($this->sessionPrefix . $sessionID, $sessionData, $this->gcMaxLifeTime); 153 $return = $this->cache()->set($this->sessionPrefix . $sessionID, $sessionData, $this->gcMaxLifeTime);
148 - var_dump($return);exit;  
149 return $return; 154 return $return;
150 } 155 }
151 156
@@ -22,10 +22,10 @@ class Session @@ -22,10 +22,10 @@ class Session
22 * @param $namespace 22 * @param $namespace
23 * @return SessionNamespace 23 * @return SessionNamespace
24 */ 24 */
25 - static public function start($namespace = 'session_default') 25 + static public function start($namespace = 'session_default', $sessionName = '_QIN')
26 { 26 {
27 if (self::isSessionStarted() == false || self::$_session == null) { 27 if (self::isSessionStarted() == false || self::$_session == null) {
28 - self::$_session = new CacheSession(); 28 + self::$_session = new CacheSession($sessionName);
29 session_start(); 29 session_start();
30 } 30 }
31 return new SessionNamespace ($namespace); 31 return new SessionNamespace ($namespace);