php get_headers help

Discussion in 'PHP' started by Dman91, Oct 5, 2008.

  1. #1
    i am trying to get all the headers from a site
    print_r(get_headers('http://example.com'));
    PHP:
    However this only returns one array of header and stops how do i make to collect all the headers ?
     
    Dman91, Oct 5, 2008 IP
  2. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why it stops? It's not stops.. :)

    For example:
    <?php
    $arr = array();
    $arr = get_headers( 'http://google.com' );
    echo $arr[0] . '<br />some text...';
    ?>
    
    Code (markup):
    So you can collect all the headers in an array...
     
    GuitarFix, Oct 5, 2008 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Pass a second argument with the value of 1 or TRUE to get_headers.
     
    joebert, Oct 5, 2008 IP
  4. GuitarFix

    GuitarFix Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    But why? The second argument of this function is "format"..
     
    GuitarFix, Oct 5, 2008 IP
  5. Dman91

    Dman91 Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Array ( [0] => HTTP/1.1 200 OK [1] => Date: Sun, 05 Oct 2008 18:18:00 GMT [2] => Server: Apache [3] => Set-Cookie: bbsessionhash=15a29a50f601ec4f74261f9cffd4f5f5; path=/; HttpOnly [4] => Set-Cookie: bblastvisit=1223230680; expires=Mon, 05-Oct-2009 18:18:00 GMT; path=/ [5] => Set-Cookie: bblastactivity=0; expires=Mon, 05-Oct-2009 18:18:00 GMT; path=/ [6] => Cache-Control: private [7] => Pragma: private [8] => Connection: close [9] => Content-Type: text/html; charset=UTF-8 ) 
    Code (markup):
    it gives something like this but it sends out more headers which it doesnt catch (ff livehttp extension)
     
    Dman91, Oct 5, 2008 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    If it doesn't display them, they weren't sent.

    The server you're fetching them from might be reacting to the USER_AGENT used by PHP to fetch the headers, and withholding headers.
     
    joebert, Oct 5, 2008 IP
  7. Dman91

    Dman91 Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    All right after using user agent it sends one more header (but it sends more headers and same result with curl with cookie)
     
    Dman91, Oct 5, 2008 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    The trick is going to be imitating the way a browser would be making the request.

    Keep looking, there's bound to be something you're missing while making the request somewhere.
     
    joebert, Oct 6, 2008 IP
  9. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    if you have curl installed use this to connect to an external site and use the setop_headers to return the headers.. with curl u can specify user agents and more to get the result you need...
     
    cornetofreak, Oct 7, 2008 IP