What are best practices for passing session IDs in URLs in PHP?

When passing session IDs in URLs in PHP, it is important to ensure that the session ID is not exposed to potential security risks, such as session fixation attacks. One way to mitigate this risk is to use session_regenerate_id() to generate a new session ID for each request. Additionally, it is recommended to store the session ID in a secure HTTP-only cookie rather than passing it in the URL.

// Start the session
session_start();

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

// Store session ID in a secure HTTP-only cookie
setcookie(session_name(), session_id(), 0, '/', '', true, true);