Created
July 28, 2012 19:01
-
-
Save stungeye/3194428 to your computer and use it in GitHub Desktop.
Simple HTTP Authentication in PHP using HTTP AUTH Headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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