How do I read any request header in PHP

Sabya picture Sabya · Feb 12, 2009 · Viewed 412k times · Source

How should I read any header in PHP?

For example the custom header: X-Requested-With.

Answer

Quassnoi picture Quassnoi · Feb 12, 2009
$_SERVER['HTTP_X_REQUESTED_WITH']

RFC3875, 4.1.18:

Meta-variables with names beginning with HTTP_ contain values read from the client request header fields, if the protocol used is HTTP. The HTTP header field name is converted to upper case, has all occurrences of - replaced with _ and has HTTP_ prepended to give the meta-variable name.