What are common methods for implementing login/logout functionality in PHP without using databases?

One common method for implementing login/logout functionality in PHP without using databases is by using session variables to store user login information. When a user logs in, their username or ID can be stored in a session variable, and when they log out, the session can be destroyed. This allows for a simple and effective way to manage user authentication without the need for a database.

<?php
session_start();

// Check if user is logged in
if(isset($_SESSION['user_id'])) {
    echo 'Welcome, ' . $_SESSION['user_id'] . '! <a href="logout.php">Logout</a>';
} else {
    echo '<a href="login.php">Login</a>';
}

// Logout functionality
if(isset($_GET['logout'])) {
    session_destroy();
    header('Location: index.php');
    exit();
}
?>