Function name: session_regenerate_id()
Applicable version: PHP 4 >= 4.3.2, PHP 5, PHP 7
Function description: The session_regenerate_id() function is used to regenerate the session ID of the current session.
Usage: session_regenerate_id([$delete_old_session = false])
parameter:
Return value: Return true if a new session ID is successfully generated; otherwise return false.
Notes:
Example:
// 开启会话session_start(); // 生成新的会话ID if (session_regenerate_id()) { echo "新的会话ID已生成"; } else { echo "无法生成新的会话ID"; } // 删除旧的会话文件if (session_regenerate_id(true)) { echo "新的会话ID已生成,并删除旧的会话文件"; } else { echo "无法生成新的会话ID"; }
In the above example, first call the session_start() function to start the session, and then call the session_regenerate_id() function to generate a new session ID. If the generation is successful, the output is "New Session ID has been generated", otherwise the output is "No new Session ID can be generated". In addition, if the $delete_old_session parameter is specified as true, the old session file will be deleted after the session ID is generated successfully.