How can the session ID be securely passed between pages in a PHP application?

To securely pass the session ID between pages in a PHP application, you can use session cookies with the Secure and HttpOnly flags set. This ensures that the session ID is only transmitted over HTTPS and cannot be accessed by client-side scripts, reducing the risk of session hijacking.

// Set session cookie parameters
session_set_cookie_params([
    'lifetime' => 0,
    'path' => '/',
    'domain' => 'yourdomain.com',
    'secure' => true, // Only transmit over HTTPS
    'httponly' => true // Cannot be accessed by client-side scripts
]);

// Start the session
session_start();