What alternative method can be used to store login status in PHP instead of using cookies?

Instead of using cookies to store login status in PHP, you can use sessions. Sessions store user data on the server-side and provide a more secure way to manage user authentication. By using sessions, you can store login status securely without exposing sensitive information to client-side scripts.

<?php
session_start();

// Check if user is logged in
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true){
    echo "User is logged in";
} else {
    echo "User is not logged in";
}

// Set login status
$_SESSION['logged_in'] = true;

// Destroy session on logout
session_destroy();
?>