dogfighter Posted November 27, 2009 Share Posted November 27, 2009 Hey all, like many of you I use the Firefox addon "Live http Headers". I'm trying to write a tool that will basically do the same thing, but web-based... so the user would enter a URL and the tool would spit out the same output that Live http Headers would have shown if you were capturing them using it. Problem is, sometimes the output from Live http Headers contains many requests of different types, for different things, on different servers. The PHP code I've been able to find in the manual pertaining to headers really only returns one (the last one). What function should I be looking at if I want it to spit out ALL of the headers and requests, a-la the Firefox addon? Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/ Share on other sites More sharing options...
trq Posted November 27, 2009 Share Posted November 27, 2009 get_headers. Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/#findComment-966359 Share on other sites More sharing options...
dogfighter Posted November 27, 2009 Author Share Posted November 27, 2009 get_headers was the first thing I tried, but like I mentioned, it only returns one header in an array. Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/#findComment-966691 Share on other sites More sharing options...
mrMarcus Posted November 28, 2009 Share Posted November 28, 2009 get_headers was the first thing I tried, but like I mentioned, it only returns one header in an array. what do you mean, "only returns one header"? Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/#findComment-966708 Share on other sites More sharing options...
oni-kun Posted November 28, 2009 Share Posted November 28, 2009 get_headers was the first thing I tried, but like I mentioned, it only returns one header in an array. It returns ALL the headers in one array, this should be very easy to parse and do much more than the 'live HTTP headers' addon. They use the same methods of retrieval, getting headers.. <?php $url = 'http://www.example.com'; print_r(get_headers($url)); print_r(get_headers($url, 1)); ?> Expected result: Array ( [0] => HTTP/1.1 200 OK [1] => Date: Sat, 29 May 2004 12:28:13 GMT [2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT [4] => ETag: "3f80f-1b6-3e1cb03b" [5] => Accept-Ranges: bytes [6] => Content-Length: 438 [7] => Connection: close [8] => Content-Type: text/html ) Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT [server] => Apache/1.3.27 (Unix) (Red-Hat/Linux) [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT [ETag] => "3f80f-1b6-3e1cb03b" [Accept-Ranges] => bytes [Content-Length] => 438 [Connection] => close [Content-Type] => text/html ) Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/#findComment-966714 Share on other sites More sharing options...
dogfighter Posted November 28, 2009 Author Share Posted November 28, 2009 Here's the output from Live HTTP Headers for loading phpfreaks.com: http://www.phpfreaks.com/ GET / HTTP/1.1 Host: www.phpfreaks.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 GTB5 (.NET CLR 3.5.30729) 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 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: PHPSESSID=8h13biq1c1g7ralbabq4us3dr3; __utma=29981182.1999759787.1259128904.1259365156.1259371994.4; __utmc=29981182; __utmz=29981182.1259302116.2.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=php%20freaks; __utmb=29981182.3.10.1259371994; phpfreaks_session=4o97q859qfiak5ptkl4n8l77e4 HTTP/1.x 200 OK Date: Sat, 28 Nov 2009 01:35:29 GMT Server: Apache/2.2.14 (EL) X-Powered-By: PHP/5.3.1 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Content-Length: 3386 Keep-Alive: timeout=2, max=100 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 ---------------------------------------------------------- http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-8794381281316343&output=html&h=600&slotname=9733596020&w=120&lmt=1259372129&flash=10.0.32&url=http%3A%2F%2Fwww.phpfreaks.com%2F&dt=1259372129950&correlator=1259372129952&frm=0&ga_vid=1999759787.1259128904&ga_sid=1259371994&ga_hid=1720423606&ga_fc=1&u_tz=-480&u_his=3&u_java=1&u_h=1050&u_w=1680&u_ah=1020&u_aw=1680&u_cd=32&u_nplug=25&u_nmime=118&biw=1663&bih=777&fu=0&ifi=1&dtd=40&xpc=nOXf61O8Ww&p=http%3A//www.phpfreaks.com GET /pagead/ads?client=ca-pub-8794381281316343&output=html&h=600&slotname=9733596020&w=120&lmt=1259372129&flash=10.0.32&url=http%3A%2F%2Fwww.phpfreaks.com%2F&dt=1259372129950&correlator=1259372129952&frm=0&ga_vid=1999759787.1259128904&ga_sid=1259371994&ga_hid=1720423606&ga_fc=1&u_tz=-480&u_his=3&u_java=1&u_h=1050&u_w=1680&u_ah=1020&u_aw=1680&u_cd=32&u_nplug=25&u_nmime=118&biw=1663&bih=777&fu=0&ifi=1&dtd=40&xpc=nOXf61O8Ww&p=http%3A//www.phpfreaks.com HTTP/1.1 Host: googleads.g.doubleclick.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 GTB5 (.NET CLR 3.5.30729) 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 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: id=22b7e6240a000034||t=1258319344|et=730|cs=ik-erpmz HTTP/1.x 200 OK P3P: policyref="http://googleads.g.doubleclick.net/pagead/gcn_p3p_.xml", CP="CURa ADMa DEVa TAIo PSAo PSDo OUR IND UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR" Content-Type: text/html; charset=UTF-8 Content-Encoding: gzip Date: Sat, 28 Nov 2009 01:35:30 GMT Server: cafe Cache-Control: private, x-gzip-ok="" Content-Length: 1890 X-XSS-Protection: 0 ---------------------------------------------------------- http://www.google-analytics.com/__utm.gif?utmwv=4.5.9&utmn=34123934&utmhn=www.phpfreaks.com&utmcs=UTF-8&utmsr=1680x1050&utmsc=32-bit&utmul=en-us&utmje=1&utmfl=10.0%20r32&utmdt=PHP%20Freaks%20-%20Index&utmhid=1720423606&utmr=-&utmp=%2F&utmac=UA-4220376&utmcc=__utma%3D29981182.1999759787.1259128904.1259365156.1259371994.4%3B%2B__utmz%3D29981182.1259302116.2.3.utmcsr%3Dgoogle%7Cutmccn%3D(organic)%7Cutmcmd%3Dorganic%7Cutmctr%3Dphp%2520freaks%3B GET /__utm.gif?utmwv=4.5.9&utmn=34123934&utmhn=www.phpfreaks.com&utmcs=UTF-8&utmsr=1680x1050&utmsc=32-bit&utmul=en-us&utmje=1&utmfl=10.0%20r32&utmdt=PHP%20Freaks%20-%20Index&utmhid=1720423606&utmr=-&utmp=%2F&utmac=UA-4220376&utmcc=__utma%3D29981182.1999759787.1259128904.1259365156.1259371994.4%3B%2B__utmz%3D29981182.1259302116.2.3.utmcsr%3Dgoogle%7Cutmccn%3D(organic)%7Cutmcmd%3Dorganic%7Cutmctr%3Dphp%2520freaks%3B HTTP/1.1 Host: www.google-analytics.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 GTB5 (.NET CLR 3.5.30729) Accept: image/png,image/*;q=0.8,*/*;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 HTTP/1.x 200 OK Date: Sat, 28 Nov 2009 01:35:30 GMT Content-Length: 35 Pragma: no-cache Cache-Control: private, no-cache, no-cache=Set-Cookie, proxy-revalidate Expires: Wed, 19 Apr 2000 11:43:00 GMT Last-Modified: Wed, 21 Jan 2004 19:50:30 GMT Content-Type: image/gif Server: Golfe X-XSS-Protection: 0 ---------------------------------------------------------- http://toolbarqueries.google.com/search?features=Rank:&sourceid=navclient-ff&client=navclient-auto-ff&googleip=O;null;172&iqrn=bzAC&querytime=Vm&orig=0_gX&ch=8c2a175f3&q=info:http%3A%2F%2Fwww.phpfreaks.com%2F GET /search?features=Rank:&sourceid=navclient-ff&client=navclient-auto-ff&googleip=O;null;172&iqrn=bzAC&querytime=Vm&orig=0_gX&ch=8c2a175f3&q=info:http%3A%2F%2Fwww.phpfreaks.com%2F HTTP/1.1 Host: toolbarqueries.google.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 GTB5 (.NET CLR 3.5.30729) GoogleToolbarFF 5.0.20090813 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 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: PREF=ID=abd8ca2f00165275:U=1ff398d2fd890de0:FF=4:TB=2:LD=en:NR=10:TM=1258319078:LM=1258692057:GM=1:S=Ywj9c5UL_pG8mnNj; NID=29=PPw2E0NsCVRaY2LHMUKw9ixx5kbboq6NjpwmpeEozF5f53wSL6O1G642LGTl97zfqv019RjlMPDsXUkjIqVWPQQAkGAN1CXJLB_2pggHy7oBD1_7ZglzeRS2E00BDYwc; TZ=480; S=static_files=3QQ4kOEUSQ4; SID=DQAAAI8AAABwjVqwbdIvtHPaWhkljOaJpC4PwNwvN-LC0KRmBKE4vB5MU4HGFSykxIrRs25gqg0BD1usUnRd6bV7RjBVFu5Okw3BbpRYf7hy3wPSwFfCVhxqDCXSAGTjK1ezdawPBx1Iu3RqblpvyolyxdOaMNXn8lIaebdMrMHjOir7VHbDQ3GiHA0IbVuvLU2UIcFHWK8; HSID=AAYE1NrZh-WqB7HZs HTTP/1.x 200 OK Cache-Control: private, max-age=0 Date: Sat, 28 Nov 2009 01:35:30 GMT Expires: -1 Content-Type: text/html; charset=ISO-8859-1 Server: gws Transfer-Encoding: chunked Content-Encoding: gzip X-XSS-Protection: 0 ---------------------------------------------------------- Here's the output from get_headers: Array ( [0] => HTTP/1.1 200 OK [1] => Date: Sat, 28 Nov 2009 01:37:49 GMT [2] => Server: Apache/2.2.14 (EL) [3] => X-Powered-By: PHP/5.3.1 [4] => Set-Cookie: phpfreaks_session=9c3pakspalriht09bl42fvjae3; expires=Sun, 28-Nov-2010 01:37:49 GMT; path=/ [5] => Expires: Thu, 19 Nov 1981 08:52:00 GMT [6] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 [7] => Pragma: no-cache [8] => Vary: Accept-Encoding,User-Agent [9] => Connection: close [10] => Content-Type: text/html; charset=UTF-8 ) Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 28 Nov 2009 01:37:49 GMT [server] => Apache/2.2.14 (EL) [X-Powered-By] => PHP/5.3.1 [set-Cookie] => phpfreaks_session=g9hj449k77vod3826d7272u6m4; expires=Sun, 28-Nov-2010 01:37:49 GMT; path=/ [Expires] => Thu, 19 Nov 1981 08:52:00 GMT [Cache-Control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0 [Pragma] => no-cache [Vary] => Accept-Encoding,User-Agent [Connection] => close [Content-Type] => text/html; charset=UTF-8 ) Notice the blocks that are missing? Specifically the ones pertaining to the calls to various google services? I need everything, including those. Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/#findComment-966743 Share on other sites More sharing options...
trq Posted November 28, 2009 Share Posted November 28, 2009 Then you will need to make requests to those sites just like your client (firefox) does. Quote Link to comment https://forums.phpfreaks.com/topic/183091-how-to-get-all-server-headers-like-live-http-headers-does/#findComment-966773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.