使用php-预定义变量AUTH_TYPE处理基本身份验证

时间:2014-08-24 08:30:27

标签: php http-headers basic-authentication

为什么在我的后续脚本中,$ _SERVER supper全局数组中没有AUTH_TYPE的索引?

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="hi please enter your password and username"');
    header('HTTP/1.1 401 Unauthorized'); // this will show the log in box
    echo 'Text to send if user hits Cancel button'; // this will show if the user click cancel 
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
    echo "<p> {$_SERVER['AUTH_TYPE']} your authentication type.</p>";
    var_dump($_SERVER) ;

}
?>

0 个答案:

没有答案