What are the potential consequences of relying solely on cookie-based session variables for user authentication in PHP applications?

Issue: Relying solely on cookie-based session variables for user authentication in PHP applications can pose a security risk as cookies can be easily manipulated by attackers. To enhance security, it is recommended to also use server-side session variables to validate user authentication.

// Start a session
session_start();

// Check if user is authenticated using server-side session variable
if(isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true){
    // User is authenticated
    // Proceed with the application
} else {
    // Redirect user to login page
    header("Location: login.php");
    exit();
}