Skip to content

Instantly share code, notes, and snippets.

@geraintp
Forked from ivanrosolen/apache_request_headers.php
Last active October 30, 2018 12:03
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 geraintp/71204c1e00a5abe9cb4adf77d65e337f to your computer and use it in GitHub Desktop.
Save geraintp/71204c1e00a5abe9cb4adf77d65e337f to your computer and use it in GitHub Desktop.
apache_request_headers
<?php
if( !function_exists('apache_request_headers') ) {
function apache_request_headers() {
$arh = array();
$rx_http = '/\AHTTP_/';
foreach($_SERVER as $key => $val) {
if( preg_match($rx_http, $key) ) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) {
foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
$rx_matches = array_map(function($str){ return ucfirst(strtolower($str)); }, $rx_matches);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return( $arh );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment