/** * 初始化 */ public function init() { if (is_string($this->cache)) { $this->cache = Sky::$app->getComponent($this->cache); } if (!$this->cache instanceof Cache) { throw new \Exception('CacheSession::cache must refer to the application component ID of a cache object.'); } parent::init(); }
/** * 更新当前的session ID 为新ID。 * 详细参见{@link http://php.net/manual/zh/function.session-regenerate-id.php} * @param boolean $deleteOldSession 是否删除旧的session */ public function regenerateID($deleteOldSession = false) { $oldID = session_id(); if (empty($oldID)) { return; } parent::regenerateID(false); $newID = session_id(); $row = $this->db->createCommand(sprintf('select * from %s where id=:id', addslashes($this->sessionTable)), array('id' => $oldID))->toList(); if (count($row)) { if ($deleteOldSession) { $this->db->createCommand(sprintf('update %s set id=:newID where id=:oldID', addslashes($this->sessionTable)), array('newID' => $newID, 'oldID' => $oldID))->exec(); } else { $this->db->createCommand(sprintf('insert into %s (id,expire,session_data) values (:id,:expire,:session_data)', addslashes($this->sessionTable)), array('id' => $newID, 'expire' => $row[0]['expire'], 'session_data' => $row[0]['session_data']))->exec(); } } else { $this->db->createCommand(sprintf('insert into %s (id,expire,session_data) values (:id,:expire,:session_data)', addslashes($this->sessionTable)), array('id' => $newID, 'expire' => time() + $this->getTimeout(), 'session_data' => ''))->exec(); } }