Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

session_regenerate_id

Description

The session_regenerate_id of Session for PHP updates the current session id with a newly generated one.

Syntax

session_regenerate_id(
    bool $delete_old_session = false
): bool

Parameters

delete_old_session

Whether to delete the old associated session file or not. You should not delete old session if you need to avoid races caused by deletion or detect/avoid session hijack attacks.

Return

Returns true on success or false on failure.

Examples

1 · void

<?

session_start();

$session_id1 = session_id();

echo "session_id1: $session_id1\n";

$return = session_regenerate_id();

var_export($return);

$session_id2 = session_id();

echo "\nsession_id2: $session_id2";

?>
session_id1: ufi6uomlm0s50oo5g9dadjs880
true
session_id2: 29ueui0k6idnf2d60k156m3jtu

2 · delete_old_session · false

<?

session_start();

$session_id1 = session_id();

echo "session_id1: $session_id1\n";

$delete_old_session = false;

$return = session_regenerate_id($delete_old_session);

var_export($return);

$session_gc = session_gc();

echo "\nsession_gc: $session_gc";

$session_id2 = session_id();

echo "\nsession_id2: $session_id2";

?>
session_id1: 944ilnklnnin3ropkp44hf1a08
true
session_gc: 58
session_id2: ih3dfpeh15td2051nuuduk40sh

3 · delete_old_session · true

<?

session_start();

$session_id1 = session_id();

echo "session_id1: $session_id1\n";

$delete_old_session = true;

$return = session_regenerate_id($delete_old_session);

var_export($return);

$session_gc = session_gc();

echo "\nsession_gc: $session_gc";

$session_id2 = session_id();

echo "\nsession_id2: $session_id2";

?>
session_id1: lqture8u398ek1ruit8mm121d0
true
session_gc: 0
session_id2: hkodi3kltpgiqagtuqvab6mnl9
HomeMenu