Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])):
  4. $fp = fopen('/log.txt', 'a+');
  5. $password = $_SERVER['PHP_AUTH_PW'];
  6. $username = $_SERVER['PHP_AUTH_USER'];
  7. $time = date('y-m-d/H:i:s');
  8. $request = $_SERVER['REDIRECT_URL'];
  9. fwrite($fp, $time."t".$request."t".$username."/".$password."rn");
  10. fclose($fp);
  11. endif;
  12.  
  13. ob_start();
  14. header("HTTP/1.1 401 Authorization Required",1);
  15. header("Status: 401 Authorization Required",1);
  16. echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  17. <html><head><title>401 Authorization Required</title></head><body>
  18. <h1>Authorization Required</h1>
  19. <p>This server could not verify that you are authorized to
  20. access the document
  21. requested. Either you supplied the wrong
  22. credentials (e.g., bad password), or your
  23. browser doesn't understand how to supply
  24. the credentials required.</p>';
  25. exit();
  26.  
  27. ?>
  28.  
  29. # script that will store invalid login attempts
  30. ErrorDocument 401 /logging.php
  31.  
  32. AuthName "Protected"
  33. AuthUserFile /etc/apache2/.htpasswd
  34. AuthType Basic
  35. Require valid-user
  36.  
  37. # Set REMOTE_USER env variable on 401 ErrorDocument
  38. RewriteEngine On
  39. RewriteBase /
  40. RewriteCond %{ENV:REDIRECT_STATUS} ^401$
  41. RewriteRule .* - [E=REMOTE_USER:%{ENV:REDIRECT_REMOTE_USER}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement