Php describes how to create a basic identity authentication site. 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 by default, most web servers are configured with anonymous access, that is, users are not prompted to identify information when accessing server 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 ):
The code is as follows:
Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow, deny
Allow from all
--------------------------------------------------------------------------------
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 below
The code is as follows:
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;
}
}
?>
Bytes. Anonymous access means...