doqw89029 2015-04-02 11:42
浏览 160

获取PHP自定义响应标头

I´m sending an ajax request with a custom header called Authorization, and I'm trying to get that header with 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;

and I get all the headers but not the custom one

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"
}

enter image description here

Any clues why I'm not getting header Authorization?

  • 写回答

1条回答 默认 最新

  • doushi8186 2015-04-02 12:05
    关注

    For custom headers the $_SERVER global in php documentation state that

    There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those

    so try to use apache_request_headers which may help you if your working with apache as a server

    Server Quote

    apache_request_headers

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line