Home >Backend Development >PHP Tutorial >Analysis of basic HTTP authentication skills in PHP, phphttp authentication skills_PHP tutorial

Analysis of basic HTTP authentication skills in PHP, phphttp authentication skills_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:31871browse

Analysis of basic HTTP authentication skills in PHP, phphttp authentication skills

This article describes the basic HTTP authentication skills in PHP with examples. Share it with everyone for your reference. The specific analysis is as follows:

Used to prevent users from accessing directories on certain servers by combining .htaccess files and .htpasswd files. These files contain information about the users allowed to access a directory and their passwords. HTTP authentication can be done by sending special HTTP header information instead of using .htaccess file
Copy code The code is as follows: If (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm="My Private Area"");
header("HTTP/1.0 401 Unauthorized");
               print "You need valid credentials to get access!n";
exit;
} else {
If (($_SERVER['PHP_AUTH_USER'] == 'mani') && ($_SERVER['PHP_AUTH_PW'] == 'w#m3nt0r')) {
                     print "Welcome to the private area!";
         } else {
header("WWW-Authenticate: Basic realm="My Private Area"");
header("HTTP/1.0 401 Unauthorized");
                      print "You need valid credentials to get access!n";
exit;
}
}
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968261.htmlTechArticleAnalysis of basic HTTP authentication skills in PHP, phphttp authentication skills This article describes the basic HTTP authentication skills in PHP with examples. Share it with everyone for your reference. The specific analysis is as follows: By combining .hta...
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