Home > Backend Development > PHP Tutorial > Code example of using base HTTP authentication in php

Code example of using base HTTP authentication in php

怪我咯
Release: 2023-03-13 22:40:01
Original
1334 people have browsed it

Introduction:

(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(); 
 }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template