This article describes how to create a basic identity authentication site in php. For more information, see
This article describes how to create a basic identity authentication site in php. For more information, see
By default, most web servers are configured with anonymous access, that is, U.S. space. When users access information on the server, they are generally not prompted to identify 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 verification, 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;
}
}
?>
, Website Space