Home  >  Article  >  Backend Development  >  Detailed explanation of how to create a basic identity authentication site in PHP_PHP Tutorial

Detailed explanation of how to create a basic identity authentication site in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:08:10770browse

By default, most web servers are generally configured for anonymous access, that is, users are generally not required to provide identification information when accessing information on the server. Anonymous access means that users can access the website without logging in with a username and password. This is also the configuration used by most public websites.
In Apache's configuration file "httpd.conf", it is configured for anonymous access by default (as shown below):

Copy the code The code is as follows:


Options Indexes FollowSymLinks Includes
AllowOverride None
Order allow,deny
Allow from all


-------------------------- -------------------------------------------------- -
To force the 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. It adds a WWW-Authenticate field to the HTTP message header. :
header("WWW-Authenticate:BASIC Realm=My Realm");
---------------- -------------------------------------------------- ----------------
Write below a copy code using
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("Wrong account/password!");
exit;
}else{
/*Get username and password for verification*/
$ user=$_SERVER['PHP_AUTH_USER'];
$pwd=$_SERVER['PHP_AUTH_PW'];
if($user=="admin"&&$pwd="password"){
echo " Passed verification";
}else{
header("HTTP/1.0 401 Unauthorized");
echo "Wrong account/password! ";
exit;
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327486.htmlTechArticleBy default, most web servers are generally configured for anonymous access, that is, when users access the server Generally, you will not be asked to prompt for identification information. Anonymous access means...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn