Guest User

Untitled

a guest
Sep 9th, 2018
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. https://user:pass@example.com/
  2. ^ ^
  3. | |---> Password
  4. |
  5. ----> Username
  6.  
  7. <?php
  8. function require_auth() {
  9. $AUTH_USER = 'user';
  10. $AUTH_PASS = 'pass';
  11. header('Cache-Control: no-cache, must-revalidate, max-age=0');
  12. $has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
  13. $is_not_authenticated = (
  14. !$has_supplied_credentials ||
  15. $_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
  16. $_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
  17. );
  18. if ($is_not_authenticated) {
  19. header('HTTP/1.1 401 Authorization Required');
  20. header('WWW-Authenticate: Basic realm="Access denied"');
  21. exit;
  22. }
  23. }
  24. require_auth();
  25. echo "entered";
  26.  
  27. ?>
Add Comment
Please, Sign In to add comment