Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active October 25, 2018 09:52
Show Gist options
  • Save jrobinsonc/76a3480066644b4afa64501362f7706c to your computer and use it in GitHub Desktop.
Save jrobinsonc/76a3480066644b4afa64501362f7706c to your computer and use it in GitHub Desktop.
PHP Basic Authentication
<?php
$auth_users = [
'sysadmin' => 'kjhgkjhgkjhg'
];
if (!isset($_SERVER['PHP_AUTH_USER']) || !array_key_exists($_SERVER['PHP_AUTH_USER'], $auth_users)
|| !isset($_SERVER['PHP_AUTH_PW']) || ($_SERVER['PHP_AUTH_PW']) !== ($auth_users[$_SERVER['PHP_AUTH_USER']])) {
header('WWW-Authenticate: Basic realm="Admin"');
header('HTTP/1.1 401 Access Denied');
echo 'Unauthorized';
exit;
}
echo 'Welcome!!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment