PHP session_regenerate_id() Function

What is session_regenerate_id Function?
How to update old session id with a new value?


The "session_regenerate_id()" function is used update the current session id with a newly generated one.


session_regenerate_id ( void )

In the above syntax, session_regenerate_id() will replace and update the current session id with a new one, and keep the current session information. Returns true on success or false on failure.

Example :

$old_sid = session_id();
$new_sid = session_id();
echo "Old Session ID: $old_sid <br />";
echo "New Session ID: $new_sid<br />";
Result :

Old Session ID: 6aa701f50afab253d6c0f813ad8134bb
New Session ID: 281a8eac37226b35cb852801cf5f01d5

In the above example, first the old session id is displayed then after using session_regenerate_id() function a regenerated id is displayed.

PHP Topics

Ask Questions

Ask Question