2

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..
  • This should answer your question: https://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php – Felix G Sep 14 '19 at 13:22
  • @DrOpossum, nah... i already read this... but... $_SERVER can get *local* data... not for incoming headers – Sunset Shimmer Sep 14 '19 at 14:55
  • `$_SERVER` can be used to get request headers passed to the webserer (and therefore PHP). You could use this to access the Authorization Header. Isn't that what you are looking for? – Felix G Sep 14 '19 at 15:00

1 Answers1

2

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'];
wbob
  • 431
  • 3
  • 9