How can PHP handle sessions without relying on cookies?

PHP can handle sessions without relying on cookies by using a technique called URL rewriting. This involves passing the session ID as a parameter in the URL for each request. This way, PHP can still track the session without needing to rely on cookies.

<?php
session_start();

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

// Continue with session handling
$_SESSION['user'] = 'John Doe';
echo 'Session ID: ' . session_id();
?>