Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

session_regenerate_id()

Assign a new identifier to an active session while preserving its current session variables.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

session_regenerate_id(bool $delete_old_session = false): bool

Assign a new identifier to an active session while preserving its current session variables. Passing true asks the handler to delete the old record. Concurrent requests using the previous identifier can then lose access to it. Failure returns false.

Signature

session_regenerate_id(bool $delete_old_session = false): bool

Example output

[true,true,2]

Examples

<?php
session_save_path(sys_get_temp_dir()); session_start(); $_SESSION["step"]=2;
$old=session_id(); $ok=session_regenerate_id(true); $changed=$old!==session_id(); $step=$_SESSION["step"]; session_destroy();
echo json_encode([$ok,$changed,$step]);

Result

[true,true,2]

Sources