How can session fixation be prevented in PHP applications that utilize session management?

Session fixation can be prevented in PHP applications by regenerating the session ID upon successful login or privilege change. This ensures that the session ID is changed after authentication, making it difficult for an attacker to fixate a session.

// Prevent session fixation by regenerating the session ID
session_regenerate_id(true);