Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active December 16, 2015 07:19
Show Gist options
  • Save chernjie/5397453 to your computer and use it in GitHub Desktop.
Save chernjie/5397453 to your computer and use it in GitHub Desktop.
apache_request_headers
<?php
print_r(apache_request_headers());
foreach ($_SERVER as $key => $val)
{
if (sscanf($key, 'HTTP_%s', $header) === 1)
{
// take SOME_HEADER and turn it into Some-Header
$header = str_replace('_', ' ', strtolower($header));
$header = str_replace(' ', '-', ucwords($header));
echo $key . ' ' . $header . ' ' . $_SERVER[$key] . "\n";
}
}
@chernjie
Copy link
Author

$ curl chernjie.localhost/apache_request_headers.php -H "dash-and_under: score" -s | column -t
Array
(
        [User-Agent]         =>      curl/7.29.0
        [Host]               =>      chernjie.localhost
        [Accept]             =>      */*
        [dash-and_under]     =>      score
)
HTTP_USER_AGENT      User-Agent      curl/7.29.0
HTTP_HOST            Host            chernjie.localhost
HTTP_ACCEPT          Accept          */*
HTTP_DASH_AND_UNDER  Dash-And-Under  score

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment