Posted By

uilgenstein on 10/14/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

pytheas
bobbym245


Apply Http Basic Auth


 / Published in: PHP
 

  1. function apply_basic_auth() {
  2. $login = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
  3. $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
  4. if(!check_credentials($login, $password)) {
  5. header('WWW-Authenticate: Basic realm="My Realm"');
  6. header('HTTP/1.0 401 Unauthorized');
  7. echo "You need to provide a valid login and password.";
  8. }
  9. }
  10.  
  11. function check_credentials($login, $password) {
  12. return $login == 'login' && $password == 'password';
  13. }

Report this snippet  

You need to login to post a comment.