【发布时间】:2013-01-21 08:37:36
【问题描述】:
在开始之前,我想指出,我浏览了 Stack Overflow 并发现了其他类似的问题 - PHP_AUTH_USER not set? 和 HTTP Auth via PHP - PHP_AUTH_USER not set? - 这些都指出身份验证 $_SERVER 变量不会如果''Server API''设置为''CGI/FCGI'',但我检查了我的''phpinfo()''输出并且我的''Server API''设置为''Apache 2.0 Handler''。
好的,我有一个简单的脚本如下:
<?php
echo "Username: " . $_SERVER["PHP_AUTH_USER"] . ", Password: " . $_SERVER["PHP_AUTH_PW"];
?>
...我通过以下方式远程调用:
wget -v --http-user=johnsmith --http-password=mypassword http://www.example.com/myscript.php
...但只输出:
Username: , Password:
我还尝试使用 PHP cURL 调用脚本并适当地设置身份验证参数,如下所示:
curl_setopt($ch, CURLOPT_USERPWD, "johnsmith:mypassword");
...但我得到与上面相同的输出。
知道我做错了什么吗?也许我还需要启用/配置其他东西?
【问题讨论】:
-
您发送的响应代码是否正确?
-
谢谢 Iganacio,您能详细说明您的意思吗?
标签: php web-services authentication basic-authentication