/** * Updates the current session ID with a newly generated one. * Please refer to <http://php.net/session_regenerate_id> for more details. * @param boolean $deleteOldSession Whether to delete the old associated session file or not. */ public function regenerateID($deleteOldSession = false) { $oldID = session_id(); // if no session is started, there is nothing to regenerate if (empty($oldID)) { return; } parent::regenerateID(false); $newID = session_id(); $collection = $this->connection->getCollection($this->sessionCollection); $row = $collection->findOne(['id' => $oldID]); if ($row !== null) { if ($deleteOldSession) { $collection->update(['id' => $oldID], ['id' => $newID]); } else { unset($row['_id']); $row['id'] = $newID; $collection->insert($row); } } else { // shouldn't reach here normally $collection->insert(['id' => $newID, 'expire' => new \MongoDate(time() + $this->getTimeout())]); } }
/** * Updates the current session ID with a newly generated one . * * Please refer to <http://php.net/session_regenerate_id> for more details. * @param boolean $deleteOldSession Whether to delete the old associated session file or not. */ public function regenerateID($deleteOldSession = false) { $oldID = session_id(); // if no session is started, there is nothing to regenerate if (empty($oldID)) { return; } parent::regenerateID(false); $newID = session_id(); $row = (new Query())->from($this->sessionTable)->where(['id' => $oldID])->createCommand($this->connection)->queryOne(); if ($row !== null) { if ($deleteOldSession) { $this->connection->createCommand()->update($this->sessionTable, ['id' => $newID], ['id' => $oldID])->execute(); } else { $row['id'] = $newID; $this->connection->createCommand()->insert($this->sessionTable, $row)->execute(); } } else { // shouldn't reach here normally $this->connection->createCommand()->insert($this->sessionTable, ['id' => $newID, 'expire' => time() + $this->getTimeout()])->execute(); } }