What is the function of the SID constant in PHP sessions and how does it affect session management when cookies are disabled?

When cookies are disabled, PHP uses the SID constant to pass the session ID via URL parameters instead. This allows session management to still function properly even when cookies are not available. The SID constant contains the session ID and is automatically appended to URLs in links and form actions.

<?php
session_start();

// Check if the session ID is passed in the URL
if(isset($_GET[session_name()])) {
    session_id($_GET[session_name()]);
}

// Use the SID constant to append the session ID to URLs
<a href="page.php?<?=htmlspecialchars(SID)?>">Link</a>
?>