Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. $LoginSuccessful = false;
  3.  
  4. // Check username and password:
  5.  
  6. if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
  7.  
  8. $Username = $_SERVER['PHP_AUTH_USER'];
  9. $Password = $_SERVER['PHP_AUTH_PW'];
  10.  
  11. if ($Username == 'jonas' && $Password == 'foobar'){
  12. $LoginSuccessful = true;
  13. }
  14. }
  15.  
  16. // Login passed successful?
  17.  
  18. if (!$LoginSuccessful){
  19. /*
  20. ** The user gets here if:
  21. **
  22. ** 1. The user entered incorrect login data
  23. ** --> User will see the error message from below
  24. **
  25. ** 2. Or the user requested the page for the first time
  26. ** --> Then the 401 headers apply and the "login box" will
  27. ** be shown
  28. */
  29.  
  30.  
  31. // The text inside the realm section will be visible for the
  32. // user in the login box
  33. header('WWW-Authenticate: Basic realm="Secret page"');
  34. header('HTTP/1.0 401 Unauthorized');
  35.  
  36. print "Login failed!n";
  37.  
  38. }
  39. else {
  40.  
  41. // The user entered the correct login data, put
  42. // your confidential data in here:
  43.  
  44. print 'you reached the secret page!';
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement