+ Reply to Thread
Results 1 to 5 of 5

Thread: request headers (php)

  1. #1

    Default request headers (php)

    Is there anyway to get the client request headers?

    I tried apache_request_headers() but it doesnt work.
    programmer in java, c++, vb6, vb.net, php, asp & mysql amongst others.

  2. #2

    Default

    Is there no way to do this using bluehost servers?

    this is essential to my current project. I must find a way to read the request headers sent by the client.

    Perhaps another serverside language can do this? I am willing to learn if there is a way.
    programmer in java, c++, vb6, vb.net, php, asp & mysql amongst others.

  3. #3
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    153

    Default

    That function is only available if PHP is installed as an Apache module, which it isn't on bluehost.

    What exactly do you need from the headers for your script to work? Perhaps there is a work-around for it as a lot of the headers are available through the $_SERVER variable.

    Edit: Actually, I did a test, $_SERVER seems to have the same data that apache_request_headers() has.
    So you could use a function like:
    PHP Code:
    function getHeaders()
    {
        
    $headers = array();
        foreach (
    $_SERVER as $k => $v)
        {
            if (
    substr($k05) == "HTTP_")
            {
                
    $k str_replace('_'' 'substr($k5));
                
    $k str_replace(' ''-'ucwords(strtolower($k)));
                
    $headers[$k] = $v;
            }
        }
        return 
    $headers;

    On my test server apache_request_headers returned:
    Code:
    Array
    (
        [Host] => localhost
        [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4
        [Accept] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
        [Accept-Language] => en-us,en;q=0.5
        [Accept-Encoding] => gzip,deflate
        [Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
        [Keep-Alive] => 300
        [Connection] => keep-alive
        [Cache-Control] => max-age=0
    )
    and that function returned:
    Code:
    Array
    (
        [Host] => localhost
        [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4
        [Accept] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
        [Accept-Language] => en-us,en;q=0.5
        [Accept-Encoding] => gzip,deflate
        [Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
        [Keep-Alive] => 300
        [Connection] => keep-alive
        [Cache-Control] => max-age=0
    )
    Last edited by lazynitwit; 07-16-2006 at 02:09 PM.
    BlueHost Knowledge Base, it is quite helpful, you should read through it.

  4. #4

    Default

    I'll try out the $_SERVER global variable, thanks.

    The problem I found is that I need to get _all_ the headers, not just traditional headers sent by the browser. The application used will send custom headers that arent used by browsers.

    this for example
    programmer in java, c++, vb6, vb.net, php, asp & mysql amongst others.

  5. #5
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    153

    Default

    Quote Originally Posted by solarnexus
    I'll try out the $_SERVER global variable, thanks.

    The problem I found is that I need to get _all_ the headers, not just traditional headers sent by the browser. The application used will send custom headers that arent used by browsers.

    this for example
    It should still work, I sent my test server the following:
    Code:
    GET /headertest.php HTTP/1.1
    Host: localhost
    Test-Header: testing
    Connection: Close
    It replied:
    Code:
    apache_request_headers():
    Array
    (
        [Host] => localhost
        [Test-Header] => testing
        [Connection] => Close
    )
    $_SERVER:
    Array
    (
        [Host] => localhost
        [Test-Header] => testing
        [Connection] => Close
    )
    Note that in the $_SERVER array it would actually be:
    Code:
    Array
    (
        [HTTP_HOST] => localhost
        [HTTP_TEST_HEADER] => testing
        [HTTP_CONNECTION] => Close
    )
    BlueHost Knowledge Base, it is quite helpful, you should read through it.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts