Skip to content

Instantly share code, notes, and snippets.

@ScottPhillips
Created January 3, 2012 07:08
Show Gist options
  • Save ScottPhillips/1553884 to your computer and use it in GitHub Desktop.
Save ScottPhillips/1553884 to your computer and use it in GitHub Desktop.
Get the headers of incoming requests using PHP
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}
?>
<?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