Last Updated: February 25, 2016
·
560
· codegefluester

Get HTTP Request Headers

When you're running on a server that does not support the PHP function apacherequestheaders this little function will do the same for you

function get_request_headers() {
    $headers = array();
    foreach($_SERVER as $k => $v) {
        if (substr($k, 0, 5) <> 'HTTP_') {
            continue;
        }

        $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($k, 5)))));
        $headers[$header] = $v;
    }
    return $headers;
}

Note that the function will change upper/lowercase so the request header installedVersion will be Installedversion.