What are the best practices for maintaining session data in PHP without relying on cookies?

When maintaining session data in PHP without relying on cookies, one common approach is to use session IDs passed through URLs or hidden form fields. This method involves generating a unique session ID for each user and passing it between pages to maintain the session state. To ensure security, it's important to validate and sanitize the session ID before using it to retrieve session data.

<?php
session_start();

// Generate a unique session ID
$session_id = uniqid();

// Pass the session ID through URLs or hidden form fields
echo '<a href="page2.php?sid=' . $session_id . '">Go to Page 2</a>';

// Validate and sanitize the session ID before using it
if(isset($_GET['sid'])) {
    $session_id = filter_var($_GET['sid'], FILTER_SANITIZE_STRING);
    // Use the session ID to retrieve session data
}
?>