How can a PHP login system be implemented without using MySQL?

Using a PHP login system without MySQL can be achieved by storing user credentials in a flat file, such as a CSV or JSON file. The PHP script can then read this file to authenticate users during the login process.

<?php
// Function to authenticate user
function authenticateUser($username, $password) {
    $users = json_decode(file_get_contents('users.json'), true);
    
    foreach ($users as $user) {
        if ($user['username'] === $username && $user['password'] === $password) {
            return true;
        }
    }
    
    return false;
}

// Example usage
if (authenticateUser('john_doe', 'password123')) {
    echo 'Login successful!';
} else {
    echo 'Invalid username or password.';
}
?>