(1) The basic web server is a template, and its role is to complete the necessary HTTP interactions between the client and the server. You can find one in the basehttpserver module The basic server class named HTTPServer
(2) The handler is some simple software that handles the main 'web service'. It is mainly used to process client requests and return appropriate files, including static files or dynamic files. The complexity of the handler determines the complexity of the web server. Basic sin is ordinary is a handler called BaseHTTPRqeuestHandler, which can be found in the BaseHTTPServer module. It contains a basic web server, which does not implement other processing work except obtaining the client's request.
This article mainly introduces the method of using base HTTP authentication in
php, involving Friends in need can refer to the related usage skills of the predefined server variable $_SERVER and header method. The details are as follows: function http_auth($un, $pw, $realm = "Secured Area")
{
if(!(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_USER'] == $un && $_SERVER['PHP_AUTH_PW'] == $pw))
{
header('WWW-Authenticate: Basic realm="$realm"');
header('Status: 401 Unauthorized');
exit();
}
}
The above is the detailed content of Code example of using base HTTP authentication in php. For more information, please follow other related articles on the PHP Chinese website!