PHP How to create a basic identity authentication site _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.