码迷,mamicode.com
首页 > Web开发 > 详细

关于$_SERVER['PHP_AUTH_USER']

时间:2017-09-08 18:13:59      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:保存   author   required   amp   user   apach   think   copy   span   

 http://www.cnblogs.com/thinksasa/p/3421379.html

PHP 的 HTTP 认证机制仅在 PHP 以 Apache 模块方式运行时才有效,因此该功能不适用于 CGI 版本。在 Apache 模块的 PHP 脚本中,可以用 header() 函数来向客户端浏览器发送“Authentication Required”信息,使其弹出一个用户名/密码输入窗口。当用户输入用户名和密码后,包含有 URL 的 PHP 脚本将会再次和预定义变量 PHP_AUTH_USER、PHP_AUTH_PW 和 AUTH_TYPE 一起被调用,这三个变量分别被设定为用户名,密码和认证类型。预定义变量保存在 $_SERVER 或者 $HTTP_SERVER_VARS 数组中。系统仅支持“基本的”认证

 

技术分享
<?php
$authorization = false;
if($_SERVER[‘PHP_AUTH_USER‘] == "admin" && $_SERVER[‘PHP_AUTH_PW‘] == "admin888"){
    echo "login";
    $authorization = true;
    exit;
}
if(!$authorization){
    header("WWW-Authenticate:Basic realm=‘Private‘");
    header(‘HTTP/1.0 401 Unauthorized‘);
    print "You are unauthorized to enter this area.";
}
?>
技术分享

关于$_SERVER['PHP_AUTH_USER']

标签:保存   author   required   amp   user   apach   think   copy   span   

原文地址:http://www.cnblogs.com/loanhicks/p/7495194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!