Created
October 8, 2010 20:21
-
-
Save pbrisbin/617465 to your computer and use it in GitHub Desktop.
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 | |
function do_auth() { | |
// prompt for password | |
header('WWW-Authenticate: Basic realm="pbrisbin dot com"'); | |
header('HTTP/1.0 401 Unauthorized'); | |
// if user cancels | |
header('Content-type: text/plain'); | |
echo 'Not authorized.'; | |
exit; | |
} | |
function authenticate($_valid_users) { | |
// credentials not known | |
if (!isset($_SERVER['PHP_AUTH_USER'])) | |
do_auth(); | |
$user = $_SERVER['PHP_AUTH_USER']; | |
$pass = $_SERVER['PHP_AUTH_PW']; | |
// user not known | |
if (!isset($_valid_users[$user])) | |
do_auth(); | |
// bad password | |
if ($_valid_users[$user] != $pass) | |
do_auth(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment