<?php
$valid_user = 'admin';
$valid_pass = '|pwc9J908R_7';

if (!isset($_SERVER['PHP_AUTH_USER'])) {
    // Fallback for CGI/FastCGI (cPanel)
    if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
        if (stripos($_SERVER['HTTP_AUTHORIZATION'], 'basic') === 0) {
            $exploded = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)), 2);
            if (count($exploded) === 2) {
                list($user, $pass) = $exploded;
                $_SERVER['PHP_AUTH_USER'] = $user;
                $_SERVER['PHP_AUTH_PW'] = $pass;
            }
        }
    }
}

if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="Restricted Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authentication required';
    exit;
}

$user = $_SERVER['PHP_AUTH_USER'];
$pass = trim($_SERVER['PHP_AUTH_PW'] ?? '');

if ($user !== $valid_user || $pass !== $valid_pass) {
    header('WWW-Authenticate: Basic realm="Restricted Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Invalid credentials';
    exit;
}
?>
