Created
November 26, 2014 18:07
-
-
Save Flygenring/3478a39f72c5fe567ca4 to your computer and use it in GitHub Desktop.
A proper drop-in replacement for apache_request_headers() when that's not available
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
<?php | |
if(!function_exists('apache_request_headers')) { | |
/// | |
function apache_request_headers() { | |
// Based on: http://www.iana.org/assignments/message-headers/message-headers.xml#perm-headers | |
$arrCasedHeaders = array( | |
// HTTP | |
'Dasl' => 'DASL', | |
'Dav' => 'DAV', | |
'Etag' => 'ETag', | |
'Mime-Version' => 'MIME-Version', | |
'Slug' => 'SLUG', | |
'Te' => 'TE', | |
'Www-Authenticate' => 'WWW-Authenticate', | |
// MIME | |
'Content-Md5' => 'Content-MD5', | |
'Content-Id' => 'Content-ID', | |
'Content-Features' => 'Content-features', | |
); | |
$arrHttpHeaders = array(); | |
foreach($_SERVER as $strKey => $mixValue) { | |
if('HTTP_' === substr($strKey, 0, 5)) { | |
$strHeaderKey = strtolower(substr($strKey, 5)); | |
$arrHeaderKey = explode('_', $strHeaderKey); | |
if(0 < count($arrHeaderKey)) { | |
$arrHeaderKey = array_map('ucfirst', $arrHeaderKey); | |
$strHeaderKey = implode('-', $arrHeaderKey); | |
} | |
else { | |
$strHeaderKey = ucfirst($strHeaderKey); | |
} | |
if(array_key_exists($strHeaderKey, $arrCasedHeaders)) { | |
$strHeaderKey = $arrCasedHeaders[$strHeaderKey]; | |
} | |
$arrHttpHeaders[$strHeaderKey] = $mixValue; | |
} | |
} | |
return $arrHttpHeaders; | |
} | |
/// | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment