【发布时间】:2015-04-02 11:42:23
【问题描述】:
我正在发送一个带有名为 Authorization 的自定义标头的 ajax 请求, 我正在尝试使用 PHP 获取该标头
if (!function_exists('getallheaders'))
{
function getallheaders()
{
$headers = array();
foreach ($_SERVER as $k => $v)
{
if (substr($k, 0, 5) == "HTTP_")
{
$k = str_replace('_', ' ', substr($k, 5));
$k = str_replace(' ', '-', ucwords(strtolower($k)));
$headers[$k] = $v;
}
}
return $headers;
}
}
$val = getallheaders();
echo $val;
我得到了所有的标题,但没有自定义一个
val: Object{
Accept: "application/json, text/plain, */*"
Accept-Encoding: "gzip, deflate, sdch"
Accept-Language: "es-ES,es;q=0.8,en;q=0.6"
Connection: "keep-alive"
Host: "www.localhost.com"
Origin: "http://localhost"
Referer: "http://localhost/gestion/"
User-Agent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
}
我没有获得标头授权的任何线索?
【问题讨论】:
-
这个问题可能在这里得到了回答:http://stackoverflow.com/questions/17488656/zend-server-windows-authorization-header-is-not-passed-to-php-script 在这个答案中,描述了一种解决方法。对你有帮助吗?
标签: php http-headers