Advertisement
Guest User

http basic auth

a guest
Jul 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. <?php
  2.  
  3. $valid_passwords = array ("captain_kirk" => "FEAKfew23q2342qfqaDSAFeafeaf");
  4. $valid_users = array_keys($valid_passwords);
  5.  
  6. $user = $_SERVER['PHP_AUTH_USER'];
  7. $pass = $_SERVER['PHP_AUTH_PW'];
  8.  
  9. $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
  10.  
  11. if (!$validated) {
  12.   header('WWW-Authenticate: Basic realm="My Realm"');
  13.   header('HTTP/1.0 401 Unauthorized');
  14.   die ("Not authorized");
  15. }
  16.  
  17. // If arrives here, is a valid user.
  18. echo "<p>Welcome $user.</p>";
  19. echo "<p>Congratulation, you are into the system.</p>";
  20.  
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement