views:

19

answers:

3

How to implement http authentication for a web app just to restrict the usage only for developers.

A: 
$LoginSuccessful = false;
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
    $Username = $_SERVER['PHP_AUTH_USER'];
    $Password = $_SERVER['PHP_AUTH_PW'];
    if ($Username == 'username_test' && $Password == 'password_test'){
        $LoginSuccessful = true;
    }
}

// Login passed successful?
if (!$LoginSuccessful){
    header('WWW-Authenticate: Basic realm="Secret page"');
    header('HTTP/1.0 401 Unauthorized');
    print "Login failed!\n";
    exit();
}

Solved my issue.. thnks...

piemesons
A: 

If Apache's htaccess is enough for you, read here.

Janne Pikkarainen
A: 

We enable .htpasswd to present a login prompt.

You can also use this if you want a module:

http://drupal.org/project/securesite

Kevin