What are the potential security risks of attaching the session ID to the URL in PHP?

Attaching the session ID to the URL in PHP can expose it to potential security risks such as session hijacking and session fixation attacks. To mitigate this risk, it is recommended to use cookies to store and transmit session IDs instead of appending them to the URL.

<?php
// Start session
session_start();

// Set session ID only in cookies
ini_set('session.use_only_cookies', 1);

// Continue with the rest of your PHP code
?>