By default, most Web servers are typically configured for anonymous access, which means that users are generally not required to prompt for identity information when accessing information on the server. Anonymous access means that users can access the site without logging in with a user name and password. This is also the configuration used by most public websites.
In the Apache configuration file "httpd.conf", the default is configured for anonymous access (see below):
Copy CodeThe code is as follows:
Options Indexes FollowSymLinks includes
AllowOverride None
Order Allow,deny
Allow from all
--------------------------------------------------------------------------------
To force a browser to use Basic authentication, you must pass a www-authenticate field, for example, the following code uses the header () function to require the client to use Basic authentication, which adds a www-authenticate field to the HTTP message header:
header ("Www-authenticate:basic realm=my Realm");
--------------------------------------------------------------------------------
Write one below to use
Copy CodeThe code is as follows:
if (!isset ($_server[' Php_auth_user ')) {
Header ("Www-authenticate:basic realm=my Realm");
Header ("http/1.0 401 Unauthorized");
Echo ("Account/Password Error! ");
Exit
}else{
/* Get user name, password to verify */
$user =$_server[' Php_auth_user '];
$pwd =$_server[' PHP_AUTH_PW '];
if ($user = = "Admin" && $pwd = "password") {
echo "Pass verification";
}else{
Header ("http/1.0 401 Unauthorized");
echo "Account/Password Error!" ";
Exit
}
}
?>
http://www.bkjia.com/PHPjc/327486.html www.bkjia.com true http://www.bkjia.com/PHPjc/327486.html techarticle by default, most Web servers are typically configured for anonymous access, which means that users are generally not required to prompt for identity information when accessing information on the server. Anonymous access means ...