How to get all server headers like Live http Headers does

dogfighter

Irish Prick
May 21, 2007
1,153
12
0
Rain City
Hey all, quick Q for any PHP gurus out there...

If you've ever used the Live HTTP Headers addon in firefox, you know it spits out all the headers, not just one. But get_headers in php only returns one in an array.

Problem is, the header I need is like the 15th one to get passed on this site. It's a GET request for a file on another server and the output from Live HTTP Headers is the only place I've been able to find it referenced.

Anyone know what function I need to be looking at to return ALL the damn headers?
 


I don't think that what you want is possible.

With Live HTTP Headers or Firebug, you're sitting on the client, and thus can see all the headers for HTTP requests and responses to and from that client.

In PHP, you're sitting on the server, and thus can see all the headers for HTTP requests and responses to and from that server. If, on a page on that server, the browser makes web requests elsewhere (you mention it's loading a page on a different server), then those headers are never sent to your server. They're exchanged directly between the user's browser and the remote server. Thus, there's no way for you to get at that data in PHP.

You'd need to do this in JavaScript, which runs in the user's browser, instead. However, due to the same-origin policy you'll be limited in what you can do with a request to another site. Without knowing exactly what you're trying to do, I can't say if it's possible or not (for instance, if you want to read/write a cookie value, this is impossible in JS, too.)
 
I don't think that what you want is possible.

With Live HTTP Headers or Firebug, you're sitting on the client, and thus can see all the headers for HTTP requests and responses to and from that client.

In PHP, you're sitting on the server, and thus can see all the headers for HTTP requests and responses to and from that server. If, on a page on that server, the browser makes web requests elsewhere (you mention it's loading a page on a different server), then those headers are never sent to your server. They're exchanged directly between the user's browser and the remote server. Thus, there's no way for you to get at that data in PHP.

You'd need to do this in JavaScript, which runs in the user's browser, instead. However, due to the same-origin policy you'll be limited in what you can do with a request to another site. Without knowing exactly what you're trying to do, I can't say if it's possible or not (for instance, if you want to read/write a cookie value, this is impossible in JS, too.)

You read it better than me then :1bluewinky:
 
Specifically which one are you looking for? You can use CURL to get a lot of the response headers and follow js redirects.
 
Yeah it would need to be something client side like javascript as zorba mentioned, php simply won't get that info server side. I'm not sure whether you could pick the headers out of their browser cache then have that info be printed and logged, then from there separate the data and print the 15th entry, but that seems like the closest solution to me from the limited description here.