How can cookies be utilized in PHP to automatically log in a user without directly accessing their Windows username?

To automatically log in a user without directly accessing their Windows username, cookies can be utilized in PHP to store a unique identifier for each user. When a user logs in, a cookie can be set with this identifier, and subsequent requests can check for the presence of this cookie to automatically log the user in without requiring their Windows username.

// Set a unique identifier for the user
$user_id = 123;

// Set a cookie with the user identifier
setcookie('user_id', $user_id, time() + (86400 * 30), '/');

// Check for the presence of the cookie to automatically log the user in
if(isset($_COOKIE['user_id'])) {
    // User is logged in
    $user_id = $_COOKIE['user_id'];
    // Perform any necessary actions for logged in user
} else {
    // User is not logged in
    // Redirect to login page or display login form
}