,執行unset($_SESSION['name'])是無法刪除的;
只有在有多個session,並且name不在首位才能被刪除,在首位的session都不能被刪除。請問這個情況大家遇到嗎?
我線上上和線下都試過,無法解決
找到問題所在了,是由於我改寫了session_set_save_handler()方法:
_cache = $cache; $this->_lifetime = ini_get('session.gc_maxlifetime'); session_set_save_handler( array($this, '_open'), array($this, '_close'), array($this, '_read'), array($this, '_write'), array($this, '_destroy'), array($this, '_gc') ); } // _open public function _open($savePath, $name) { return true; } // _close public function _close() { $this->_gc($this->_lifetime); return true; } // _read public function _read($id) { $res = $this->_cache->get(self::CACHE_KEY . $id, FALSE); return $res ? $res : ''; } // _write public function _write($id, $value) { if ($value) { $flag = $this->_cache->set(self::CACHE_KEY . $id, $value, intval($this->_lifetime), FALSE); return $flag; } else { return FALSE; } } // _destroy public function _destroy($id) { $flag = $this->_cache->delete(self::CACHE_KEY . $id); return $flag; } // _gc public function _gc($lifetime) { }}
調用:
$cache = load_cache(); // 返回Redis對象$handle = new Session_Redis($cache);
代碼有什麼問題嗎?
回複內容:
,執行unset($_SESSION['name'])是無法刪除的;
只有在有多個session,並且name不在首位才能被刪除,在首位的session都不能被刪除。請問這個情況大家遇到嗎?
我線上上和線下都試過,無法解決
找到問題所在了,是由於我改寫了session_set_save_handler()方法:
_cache = $cache; $this->_lifetime = ini_get('session.gc_maxlifetime'); session_set_save_handler( array($this, '_open'), array($this, '_close'), array($this, '_read'), array($this, '_write'), array($this, '_destroy'), array($this, '_gc') ); } // _open public function _open($savePath, $name) { return true; } // _close public function _close() { $this->_gc($this->_lifetime); return true; } // _read public function _read($id) { $res = $this->_cache->get(self::CACHE_KEY . $id, FALSE); return $res ? $res : ''; } // _write public function _write($id, $value) { if ($value) { $flag = $this->_cache->set(self::CACHE_KEY . $id, $value, intval($this->_lifetime), FALSE); return $flag; } else { return FALSE; } } // _destroy public function _destroy($id) { $flag = $this->_cache->delete(self::CACHE_KEY . $id); return $flag; } // _gc public function _gc($lifetime) { }}
調用:
$cache = load_cache(); // 返回Redis對象$handle = new Session_Redis($cache);
代碼有什麼問題嗎?
沒有遇到過,你確認下是不是被重建了,可以unset($_SESSION['name'])以後,給$_SESSION['name']重新賦值試試。