session_regenerate_id — Updating Existing Session ID with a New One in PHP
The article explains PHP's session_regenerate_id() function, its optional delete_old_session parameter, return values, and provides a complete code example demonstrating how to replace the current session ID while preserving session data.
The PHP function session_regenerate_id() replaces the current session ID with a newly generated one without altering the session data.
Parameter: $delete_old_session (bool) determines whether the old session storage file is removed.
Return value: Returns TRUE on success, FALSE on failure.
Example:
<?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);
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
