Last active
November 30, 2015 02:28
-
-
Save tqyq/6c6a368cc2cff4c6089c to your computer and use it in GitHub Desktop.
php get http header value by key
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
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