How can PHP handle user authentication without relying on a separate MySQL database for storing user credentials?

When handling user authentication without relying on a separate MySQL database, one possible solution is to store user credentials directly within the PHP code using an associative array or another data structure. This approach eliminates the need for an external database but may not be as secure or scalable as using a database management system.

<?php

// User credentials stored in an associative array
$users = [
    'username1' => 'password1',
    'username2' => 'password2',
    'username3' => 'password3'
];

// Check if the user input matches the stored credentials
$username = $_POST['username'];
$password = $_POST['password'];

if (array_key_exists($username, $users) && $users[$username] === $password) {
    echo 'Authentication successful';
} else {
    echo 'Authentication failed';
}