Home  >  Article  >  Backend Development  >  Analysis of basic HTTP authentication techniques in PHP_PHP tutorial

Analysis of basic HTTP authentication techniques in PHP_PHP tutorial

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

Analysis of basic HTTP authentication techniques in PHP

This article mainly introduces the basic HTTP authentication techniques in PHP, and analyzes the principles and implementation methods of HTTP authentication with examples, which has certain reference For reference value, friends in need can refer to it

The examples in this article describe basic HTTP authentication techniques in PHP. 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

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/968666.htmlTechArticleAnalysis of basic HTTP authentication skills in PHP This article mainly introduces the basic HTTP authentication skills in PHP and analyzes HTTP with examples The principles and implementation methods of identity verification have certain reference value and need to be...
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