Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. RewriteEngine on
  2. RewriteRule ^.*$ - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
  3.  
  4. <?php
  5.  
  6. if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basics+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) {
  7. list($name, $password) = explode(':', base64_decode($matches[1]));
  8. $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
  9. $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
  10. }
  11.  
  12. //set http auth headers for apache+php-cgi work around if variable gets renamed by apache
  13. if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basics+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
  14. list($name, $password) = explode(':', base64_decode($matches[1]));
  15. $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
  16. $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
  17. }
  18.  
  19.  
  20.  
  21. if (!isset($_SERVER['PHP_AUTH_USER'])) {
  22. header('WWW-Authenticate: Basic realm="My Realm"');
  23. header('HTTP/1.0 401 Unauthorized');
  24. echo 'Text to send if user hits Cancel button';
  25. exit;
  26. } else {
  27. echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
  28. echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement