How can PHP be used to create a login system that allows for multiple usernames and passwords without using a database?

To create a login system in PHP without using a database for multiple usernames and passwords, you can store the credentials in an associative array within the PHP script. When a user tries to log in, you can check if the entered username and password match any of the entries in the array.

<?php

$users = array(
    'user1' => 'password1',
    'user2' => 'password2',
    'user3' => 'password3'
);

if(isset($_POST['username']) && isset($_POST['password'])){
    $username = $_POST['username'];
    $password = $_POST['password'];

    if(array_key_exists($username, $users) && $users[$username] == $password){
        echo 'Login successful!';
    } else {
        echo 'Invalid username or password';
    }
}

?>