What are the best practices for embedding session IDs in URLs in PHP?

When embedding session IDs in URLs in PHP, it is important to ensure that the session ID is secure and not easily accessible to potential attackers. One way to achieve this is by using session_regenerate_id() to generate a new session ID for each request, preventing session fixation attacks. Additionally, it is recommended to use session_set_cookie_params() to set secure and HttpOnly flags for the session cookie to enhance security.

// Start the session
session_start();

// Regenerate session ID to prevent session fixation attacks
session_regenerate_id();

// Set secure and HttpOnly flags for the session cookie
session_set_cookie_params([
    'secure' => true,
    'httponly' => true
]);