Home > Backend Development > PHP Tutorial > 请教这个程序有什么有关问题?为什么运行不成功

请教这个程序有什么有关问题?为什么运行不成功

WBOY
Release: 2016-06-13 13:17:26
Original
875 people have browsed it

请问这个程序有什么问题?为什么运行不成功?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $authorized = false;

    if (isset($_SERVER["PHP_AUTH_USER"]) && isset($_SERVER["PHP_AUTH_PW"])) {
        $authFile = file("D:/li.txt");
        
        if (in_array($_SERVER["PHP_AUTH_USER"].":".$_SERVER["PHP_AUTH_PW"]."\n", $authFile))
            $authorized = true;
    }
    
    if (! $authorized) {
        header("WWW-Authenticate: Basic Realm=输入用户名与密码");
        header("HTTP/1.0 401 Unauthorized");
        
        print("You must provide the proper credentials!");
        exit;
    }
?>

Copy after login


我的d:\li.txt文件:
jason:60d99e58d66a5e0f4f89ec3ddd1d9a80
donald:d5fc4b0e45c8f9a333c0056492c191cf
mickey:bc180dbc583491c00f8a1cd134f7517b


输入用户名与密码后却$authorized=false,一直弹出输入框表示输入,三次后却显示You must provide the proper credentials!表示输入错误。。。

------解决方案--------------------
你确定你输入的密码是 60d99e58d66a5e0f4f89ec3ddd1d9a80 这样的吗?
这个是应该是加密后的密码,而 $_SERVER["PHP_AUTH_PW"] 则是未经处理过的明文
------解决方案--------------------
那么长的密码串,你能保证不输错?

$authFile = file("D:/li.txt");
显然你是在 window 下工作
那么行结束处除了新行“\n”还有回车“\r”
你没计算进去,如何能正确匹配?
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