By default, most web servers are configured with anonymous access, that is, user information on the server is not prompted to identify the information. Anonymous access means that users can access the website without using their usernames and passwords. This is also the configuration used by most public websites.
In the Apache configuration file "httpd. conf", anonymous access is configured by default (as follows ):
Copy codeThe Code is as follows: <directory "C:/program files/Apache software foundation/apache2.2/htdocs">
Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow, deny
Allow from all
</Directory>
--------------------------------------------------------------------------------
To force the browser to use BASIC identity authentication, a WWW-Authenticate field must be passed. For example, the following code uses the header () function to require the client to use BASIC authentication, it adds a WWW-Authenticate field to the HTTP message header:
Header ("WWW-Authenticate: BASIC Realm = My Realm ");
--------------------------------------------------------------------------------
Write a usage example belowCopy codeThe Code is as follows: <? Php
If (! Isset ($ _ SERVER ['php _ AUTH_USER ']) {
Header ("WWW-Authenticate: BASIC Realm = My Realm ");
Header ("HTTP/1.0 401 Unauthorized ");
Echo ("incorrect account/password! ");
Exit;
} Else {
/* Obtain the user name and password for verification */
$ User = $ _ SERVER ['php _ AUTH_USER '];
$ Pwd = $ _ SERVER ['php _ AUTH_PW '];
If ($ user = "admin" & $ pwd = "password "){
Echo "verified ";
} Else {
Header ("HTTP/1.0 401 Unauthorized ");
Echo "incorrect account/password! ";
Exit;
}
}
?>