Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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();
- }
- ?>
Add Comment
Please, Sign In to add comment