Home > Backend Development > PHP Tutorial > How to use base HTTP authentication in php_PHP tutorial

How to use base HTTP authentication in php_PHP tutorial

WBOY
Release: 2016-07-13 09:56:38
Original
749 people have browsed it

How to use base HTTP verification in php

This article mainly introduces the method of using base HTTP verification in php, involving the predefined server variable $_SERVER and the header method. For usage tips, friends in need can refer to them

The example in this article describes the method of using base HTTP authentication in PHP. Share it with everyone for your reference. The details are as follows:

 ?

1

2

3

4

5

6

7

8

9

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();

}

}

1

2 3

45 6 7 8 9
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(); } }
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/987099.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/987099.htmlTechArticleHow to use base HTTP authentication in php. This article mainly introduces the method of using base HTTP authentication in php, involving Related usage skills of predefined server variables $_SERVER and header methods require...
Related labels:
php
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