Page 1 of 1

Getting all headers w/php

Posted: Thu Aug 01, 2013 9:41 pm
by inosent1
Hi

when i use livehttpheaders i get the following

Code: Select all


// PART 1
http://www.thesite.com/the_page.html

GET /the_page.html HTTP/1.1
Host: http://www.thesite.com
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Firefox/17.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Cookie: __cfduid=dbe50c0c69cc696be75f57edfafa10fd81375403991; __gads=ID=1a02ee2637fc796b:T=1375403992:S=ALNI_Mbo-WSQLc3M2i2MshXDtgHi2OgDAw; __utma=130432987.745463861.1375404158.1375404158.1375406294.2; __utmc=130432987; __utmz=130432987.1375404161.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); vnd=; qsgr=1; qidxr=1; QUADIDX=3; qsg=13158060

// PART 2


HTTP/1.1 301 Moved Permanently
Server: cloudflare-nginx
Date: Fri, 02 Aug 2013 02:23:54 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Location: /some_other_folder/123456
Set-Cookie: vnd=; path=/
CF-RAY: 9774f0a91b90077


but all the code i have tried using php to get the header only gives me [PART 1] above, but i need [PART 2] because in that header, where you see Location there is a trailing number after where it says "some_other_folder/"

although i have tried countless exotic functions, using every imaginable device, they all output the same thing, they never move past PART 1 (as i call it) to PART 2, or the next header in the 'header chain' so to speak.

so no matter the code, they all end up with the same thing as this code gives me:

Code: Select all

<?
$url='http://whatever_site_you_want.com';

print_r(get_headers($url));

print_r(get_headers($url, 1));


any ideas appreciated!

TIA

Re: Getting all headers w/php

Posted: Fri Aug 02, 2013 9:08 am
by AbraCadaver

Re: Getting all headers w/php

Posted: Fri Aug 02, 2013 12:28 pm
by requinix
cURL can do it too with a combination of CURLOPTions, exactly what escaping me at the moment - like maybe CURLINFO_HEADER_OUT and CURLOPT_FOLLOWLOCATION? I bet the built-in streams and stream contexts can too.

Absolute worst case that I'm sure you wouldn't have to fall back to is handling the redirections yourself: loop until you get a non-3xx response, and while you do grab the Location: header, figure out the new URL (as Location: often does not have a fully-qualified URL), and fetch that.