简体   繁体   中英

How to get headers from incoming php request

I'm trying to get headers ( authorization row from headers) from incoming php request (php://input) but can't get it.

i'm trying that:

get_headers('php://input');

but i had error

get_headers(): This function may only be used against URLs in /path..

with PHP 7.3 the function getallheaders() can now be used in a (nginx) php-fpm context too and is no longer restricted to Apache only, so for most users this is an easy pick if they are on >= 7.3. A polyfill exists that uses the $_SERVER global if you cannot upgrade to PHP 7.3 yet that is similar to what is proposed in the answer linked in the comments. (beware of case-sensitiveness though)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM