framework/web/DbSession.php
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();
        // if session id regeneration failed, no need to create/update it.
        if (empty($newID)) {
            Yii::warning('Failed to generate new session ID', __METHOD__);
            return;
        }

        $row = $this->db->useMaster(function() use ($oldID) {
            return (new 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();
        }
    }
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();
        // if session id regeneration failed, no need to create/update it.
        if (empty($newID)) {
            Yii::warning('Failed to generate new session ID', __METHOD__);
            return;
        }

        $row = $this->db->useMaster(function() use ($oldID) {
            return (new 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();
        }
    }
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 ( ) ; // if session id regeneration failed, no need to create/update it. if ( empty ( $ newID ) ) { Yii :: warning ( 'Failed to generate new session ID' , __METHOD__ ) ; return ; } $ row = $ this -> db -> useMaster ( function ( ) use ( $ oldID ) { return ( new 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 ( ) ; } }
Updates the current session ID with a newly generated one .
Please refer to <https://secure.php.net/session_regenerate_id> for more details.
@param bool $deleteOldSession Whether to delete the old associated session file or not.
Updates the current session ID with a newly generated one . Please refer to <https : // secure . php . net / session_regenerate_id > for more details .