Forum Moderators: coopster

Message Too Old, No Replies

detecting http headers?

         

disgust

9:40 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



I want to know how to detect http headers- NOT how to send them out.

anyone care to clue me in? or even better, explain how on earth I can normally answer a question like this for myself? (I tried googling, and didn't have any luck)

jollymcfats

9:50 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



The headers are in the $_SERVER[''] global array, with 'HTTP_' prepended to the name. E.g.: $_SERVER['HTTP_USER_AGENT'].

This isn't particularly glaring in the documentation, but you'll find more details in the "predefined variables" section of the PHP manual.

jollymcfats

9:58 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



You'll also find more info in the CGI specification, though there isn't much more to tell. CGI translates incoming HTTP headers into environment variables named HTTP_ plus the header in all caps, hypens into underscores. There's probably some rules about how it adds headers together if more of one kind are sent. (Cookie:, perhaps.)

PHP provides CGI-style access to the headers through $_SERVER or $_ENV, regardless of whether PHP itself is running as a CGI or server module.

disgust

10:11 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



the specific header I was interested in was the location/redirect one. however, that doesn't seem to be listed in the php manual?

also, there's a "get_headers" listed on php.net but whenever I use it (even if exactly as mentioned), I get a "fatal error, function not defined" or something?

jollymcfats

10:35 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



Location is an outgoing-only HTTP header. Are you wanting to check to see if your script has already set a Location header? You could use the headers_list() function (PHP 5 only).

On the inbound side, there's no way of knowing if a request was redirected to you. You could look at the referer header and do some guesswork.

disgust

10:36 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



no, I'd like to check what location headers (if any) are sent out by a particular url.. if that makes sense

jollymcfats

10:38 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



You can connect to the URL with curl and you can get the full list of headers sent back.

mincklerstraat

9:51 am on Oct 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



@disgust:

get_headers() is php5 only - when you're at php.net and looking at the functions, under the function name you'll see which versions of php the function is available on.

If it's you who wants to know what the headers are, and not your script who wants to know, get firefox, and install the webdev extension. Under info there's 'view response headers.' I use this all the time, very very handy.

jamesa

12:53 pm on Oct 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of PHP you could install tcpflow which let's you see *all* the raw data that's coming to and from your server.