session_regenerate_id

(PHP 4 >= 4.3.2, PHP 5, PHP 7)
Update the current session id with a newly generated one
bool session_regenerate_id ([ bool $delete_old_session = false ] )

session_regenerate_id() will replace the current session id with a new one, and keep the current session information.

When session.use_trans_sid is enabled, output must be started after session_regenerate_id() call. Otherwise, old session ID is used.

Parameters:
delete_old_session

Whether to delete the old associated session file or not.

Returns:

Returns TRUE on success or FALSE on failure.

Changelog:
4.3.3

Since then, if session cookies are enabled, use of session_regenerate_id() will also submit a new session cookie with the new session id.

5.1.0

Added the delete_old_session parameter.

Examples:
A session_regenerate_id() example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
session_start();
 
$old_sessionid = session_id();
 
session_regenerate_id();
 
$new_sessionid = session_id();
 
echo "Old Session: $old_sessionid<br />";
echo "New Session: $new_sessionid<br />";
 
print_r($_SESSION);
?>
See also:

session_id() -

session_start() -

session_name() -

doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.