Last Updated: February 25, 2016
·
678
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside