Skip to content

Instantly share code, notes, and snippets.

@abrahamvegh
Last active December 14, 2015 00:39
Show Gist options
  • Save abrahamvegh/5000816 to your computer and use it in GitHub Desktop.
Save abrahamvegh/5000816 to your computer and use it in GitHub Desktop.
Return received HTTP headers as JSON
<?
function normalize_header_name ($name)
{
$name = substr($name, 5);
$name = str_replace('_', '-', $name);
$name = strtolower($name);
return $name;
}
$headers = array();
foreach ($_SERVER as $name => $value)
if (preg_match('/^HTTP_/', $name)) $headers[normalize_header_name($name)] = $value;
header('Content-type: application/json');
echo json_encode($headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment