What potential issues can arise when passing sessions through the URL in PHP?

Passing sessions through the URL in PHP can pose security risks as the session ID is exposed in the URL, making it vulnerable to session hijacking or fixation attacks. To mitigate this risk, it is recommended to use cookies to store session IDs instead of passing them through the URL.

// Set session ID in a cookie instead of passing it through the URL
session_start();

// Set session ID in a cookie with httponly flag to prevent XSS attacks
setcookie(session_name(), session_id(), 0, '/', '', true);