Skip to content

Instantly share code, notes, and snippets.

@tqyq
Last active November 30, 2015 02:28
Show Gist options
  • Save tqyq/6c6a368cc2cff4c6089c to your computer and use it in GitHub Desktop.
Save tqyq/6c6a368cc2cff4c6089c to your computer and use it in GitHub Desktop.
php get http header value by key
function head_value($key) {
$headers = [];
if (!function_exists('getallheaders')) {
foreach ($_SERVER as $name => $value) {
/* RFC2616 (HTTP/1.1) defines header fields as case-insensitive entities. */
if (strtolower(substr($name, 0, 5)) == 'http_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
} else {
$headers = getallheaders();
}
return $headers[$key];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment