Skip to content

Instantly share code, notes, and snippets.

@stungeye
Created July 28, 2012 19:01
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stungeye/3194428 to your computer and use it in GitHub Desktop.
Save stungeye/3194428 to your computer and use it in GitHub Desktop.
Simple HTTP Authentication in PHP using HTTP AUTH Headers
<?php
define('ADMIN_LOGIN','wally');
define('ADMIN_PASSWORD','mypass'); // Could be hashed too.
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])
|| ($_SERVER['PHP_AUTH_USER'] != ADMIN_LOGIN)
|| ($_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD)) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Password For Blog"');
exit("Access Denied: Username and password required.");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment