Are there any security risks associated with passing session variables in URLs?

Passing session variables in URLs can pose security risks as they can easily be intercepted by third parties or stored in browser history. To mitigate this risk, it is recommended to use cookies to store session variables instead of passing them in URLs. This helps to keep sensitive information secure and inaccessible to unauthorized users.

// Start the session
session_start();

// Set session variable
$_SESSION['username'] = 'example';

// Set cookie to store session ID
setcookie(session_name(), session_id(), time() + 3600, '/');