How can user identification be implemented in PHP without relying on cookies?
User identification in PHP can be implemented without relying on cookies by using sessions. Sessions store user data on the server side and assign a unique session ID to each user, which is then passed back and forth between the client and server. This allows for secure user identification without the need for cookies.
<?php
session_start();
// Check if a session ID is already assigned to the user
if (!isset($_SESSION['user_id'])) {
// Generate a unique user ID
$user_id = uniqid();
// Assign the user ID to the session
$_SESSION['user_id'] = $user_id;
}
// Use $_SESSION['user_id'] to identify the user throughout their session
echo "User ID: " . $_SESSION['user_id'];
?>