Thursday, March 31, 2011

How do I read any request header in PHP

How should I read any header in PHP?

For example the custom header: X-Requested-With.

From stackoverflow
  • $_SERVER['HTTP_X_REQUESTED_WITH']
    
  • Google hit #1

    http://www.php.net/apache_request_headers

    <?php
    $headers = apache_request_headers();
    
    foreach ($headers as $header => $value) {
        echo "$header: $value <br />\n";
    }
    ?>
    

    See Also

    apache_response_headers() - Fetch all HTTP response headers

    alex : I assume this is only when using the Apache server... might need to let the OP know that :)
    Jacco : I was hoping he would do some reading for himself.

0 comments:

Post a Comment