yii\web\DbSession::regenerateID PHP Method

regenerateID() public method

Please refer to for more details.
public regenerateID ( boolean $deleteOldSession = false )
$deleteOldSession boolean 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();
        $query = new Query();
        $row = $query->from($this->sessionTable)->where(['id' => $oldID])->createCommand($this->db)->queryOne();
        if ($row !== false) {
            if ($deleteOldSession) {
                $this->db->createCommand()->update($this->sessionTable, ['id' => $newID], ['id' => $oldID])->execute();
            } else {
                $row['id'] = $newID;
                $this->db->createCommand()->insert($this->sessionTable, $row)->execute();
            }
        } else {
            // shouldn't reach here normally
            $this->db->createCommand()->insert($this->sessionTable, $this->composeFields($newID, ''))->execute();
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * 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)
 {
     if ($this->dbSession) {
         return $this->dbSession->regenerateID($deleteOldSession);
     } else {
         parent::regenerateID($deleteOldSession);
     }
 }