/** * Updates the current session id with a newly generated one. * Please refer to {@link http://php.net/session_regenerate_id} for more details. * @param boolean $deleteOldSession Whether to delete the old associated session file or not. * @since 1.1.8 */ public function regenerateID($deleteOldSession = false) { $oldID = $this->getId(); // if no session is started, there is nothing to regenerate if (empty($oldID)) { return; } parent::regenerateID(false); $newID = $this->getId(); $session = Session::objects()->filter(['id' => $oldID])->get(); if ($session !== null) { if ($deleteOldSession) { $session->objects()->update(['id' => $newID]); } else { $session->id = $newID; $session->save(); } } else { $session = new Session(['id' => $newID, 'data' => '']); $session->save(); } }
/** * Session write handler. * Do not call this method directly. * @param string $session_id session ID * @param string $session_data session data * @throws Exception * @return boolean whether session write is successful */ public function write($session_id, $session_data) { // exception must be caught in session write handler // http://us.php.net/manual/en/function.session-set-save-handler.php $expire = time() + (int) ini_get('session.gc_maxlifetime'); if ($this->encrypt) { $session_data = mcrypt_encrypt(MCRYPT_3DES, $this->key, $session_data, MCRYPT_MODE_ECB); } $session = Session::objects()->get(['id' => $session_id]); if ($session === null) { $session = new Session(['id' => $session_id, 'data' => $session_data, 'expire' => $expire]); if ($session->save() === false) { throw new Exception("Can't create session"); } } else { Session::objects()->filter(['id' => $session_id])->update(['data' => $session_data, 'expire' => $expire]); } return true; }