Current Location: Home> Function Categories> session_regenerate_id

session_regenerate_id

Update the current session ID with the newly generated session ID
Name:session_regenerate_id
Category:Session Session
Programming Language:php
One-line Description:Regenerate the session ID of the current session

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:

  • $delete_old_session (optional): A boolean value that specifies whether to delete old session files. The default value is false, which means that the old session file is not deleted.

Return value: Return true if a new session ID is successfully generated; otherwise return false.

Notes:

  1. Before calling the session_regenerate_id() function, the session_start() function must be called to start the session.
  2. After the new session ID is generated, the old session ID will be invalid, but the session data will be retained.
  3. If the $delete_old_session parameter is specified as true, the old session file will be deleted.

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.

Similar Functions
Popular Articles