Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?
  2. $auth = false; // Assume user is not authenticated
  3. if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
  4.     $filename = 'passfile.txt';
  5.     $file_contents = file($filename);
  6.     foreach ($file_contents as $line) {
  7.         list($username, $password) = explode(':', $line);
  8.         $username = trim($username);
  9.         $password = trim($password);
  10.         if (($username == "$PHP_AUTH_USER") && ($password == "$PHP_AUTH_PW")) {
  11.             $auth = true;
  12.             break;
  13.         }
  14.     }
  15. }
  16. if (!$auth) {
  17.     header('WWW-Authenticate: Basic realm="Calendar"');
  18.     header('HTTP/1.0 401 Unauthorized');
  19.     die('<p>&nbsp;</p><p><center><h1><font color ="red">Authorization Required.</h1><br>Please close this window to try again.</center></font></P>');
  20. } else {
  21. // do something
  22. }
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement