Return to Snippet

Revision: 33878
at October 14, 2010 19:16 by uilgenstein


Updated Code
function apply_basic_auth() {
  $login = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
  $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
  if(!check_credentials($login, $password)) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo "You need to provide a valid login and password.";
    exit;
  }
}

function check_credentials($login, $password) {
  return $login == 'login' && $password == 'password';
}

Revision: 33877
at October 14, 2010 19:14 by uilgenstein


Initial Code
function apply_basic_auth() {
  $login = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
  $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
  if(!check_credentials($login, $password)) {
    header('WWW-Authenticate: Basic realm="OfficeConfigurator"');
    header('HTTP/1.0 401 Unauthorized');
    echo "You need to provide a valid login and password.";
    exit;
  }
}

Initial URL

                                

Initial Description

                                

Initial Title
Apply Http Basic Auth

Initial Tags

                                

Initial Language
PHP