Guest User

Untitled

a guest
Jun 17th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2.  
  3. function do_auth() {
  4. // prompt for password
  5. header('WWW-Authenticate: Basic realm="pbrisbin dot com"');
  6. header('HTTP/1.0 401 Unauthorized');
  7.  
  8. // if user cancels
  9. header('Content-type: text/plain');
  10. echo 'Not authorized.';
  11. exit;
  12. }
  13.  
  14. function authenticate($_valid_users) {
  15. // credentials not known
  16. if (!isset($_SERVER['PHP_AUTH_USER']))
  17. do_auth();
  18.  
  19. $user = $_SERVER['PHP_AUTH_USER'];
  20. $pass = $_SERVER['PHP_AUTH_PW'];
  21.  
  22. // user not known
  23. if (!isset($_valid_users[$user]))
  24. do_auth();
  25.  
  26. // bad password
  27. if ($_valid_users[$user] != $pass)
  28. do_auth();
  29. }
  30.  
  31. ?>
Add Comment
Please, Sign In to add comment