What is the purpose of session_regenerate_id() function in PHP and how does it enhance session security?
The session_regenerate_id() function in PHP is used to regenerate the session ID of the current session. This helps enhance session security by preventing session fixation attacks, where an attacker can hijack a user's session by knowing their session ID. By regenerating the session ID, the attacker's knowledge of the old session ID becomes useless.
// Regenerate session ID to enhance security
session_regenerate_id(true);