Simple credentials checking: : Authentication « HTML « PHP






Simple credentials checking:

 
<?
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header("WWW-Authenticate: Basic realm=\"Private Area\"");
            header("HTTP/1.0 401 Unauthorized");
            print "Sorry - you need valid credentials to be granted access!\n";
            exit;
    } else {
            if (($_SERVER['PHP_AUTH_USER'] == 'A') &&
                    ($_SERVER['PHP_AUTH_PW'] == 'B')) {
                    print "Welcome to the private area!";
            } else {
                    header("WWW-Authenticate: Basic realm=\"Private Area\"");
                    header("HTTP/1.0 401 Unauthorized");
                    print "Sorry - you need valid credentials to be granted access!\n";
                    exit;
            }
    }
?>
  
  








Related examples in the same category

1.Authentication Over HTTP
2.Basic authentication prompt
3.Checking the values returned from the authentication prompt
4.Get Users from users table
5.Enforcing Basic authentication
6.HTTP Authentication example
7.HTTP Authentication example forcing a new name/password
8.Hardcoding the username and password into a script
9.If user logged in
10.Only One Username and Password Is Valid
11.Usernames and Passwords Are Checked Against Data in a Database
12.Usernames and Passwords Are Checked Against Data in a File
13.Using HTTP authentication with a PHP script
14.Use database to store user name and password
15.The Username and Password Are Retrieved for Both Apache and IIS
16.User management with database