Created
January 3, 2012 07:08
-
-
Save ScottPhillips/1553884 to your computer and use it in GitHub Desktop.
Get the headers of incoming requests using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$headers = apache_request_headers(); | |
foreach ($headers as $header => $value) { | |
echo "$header: $value <br />\n"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getHeaders() { | |
$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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment