How can one use cookies in PHP to remember a user's login information?

To remember a user's login information using cookies in PHP, you can set a cookie with the user's username or ID when they log in. When the user returns to the site, you can check for the presence of this cookie and automatically log them in if it exists.

// Set a cookie with the user's username when they log in
setcookie('username', $username, time() + 3600); // cookie expires in 1 hour

// Check for the presence of the cookie and log the user in if it exists
if(isset($_COOKIE['username'])){
    $username = $_COOKIE['username'];
    // Perform login logic using the username
}