选择身份验证标头PHP

时间:2015-08-11 09:09:24

标签: php

我在每个请求的标头中发送一个令牌,当我执行print_r(apache_request_headers());时,我得到了...

[Host] => 192.168.100.100 
[Connection] => keep-alive 
[Authorization] =>d868cbf31f676130649fbfd7fff64a70cc071cd0fc8afa676b ... 
[Origin] => null 
[User-Agent] => Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 
[Accept] => */* 
[Accept-Encoding] => gzip, deflate, sdch [Accept-Language] => en-US,en;q=0.8 )

我已尝试echo $_SERVER['Authorization'];,但收到错误Undefined index: Authorization

我如何获得令牌。

2 个答案:

答案 0 :(得分:0)

您可以使用array dereferencing (PHP >= 5.4),例如

echo apache_request_headers()["Authorization"];

或者将其分配给变量a然后访问它,例如

$headers = apache_request_headers();
echo $headers["Authorization"];

答案 1 :(得分:0)

试试这个,它是服务器无关的

$header = getallheaders();
echo $header['Authorization'];