Skip to content

Instantly share code, notes, and snippets.

@Flygenring
Created November 26, 2014 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flygenring/3478a39f72c5fe567ca4 to your computer and use it in GitHub Desktop.
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
<?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