PHP: HTTP_HOST vs. SERVER_NAME

PHP: HTTP_HOST vs. SERVER_NAME

Posted by: BGilkison
Posted on: 2003-02-04 14:24:00

Philosphically speaking, I'm looking for some guru-thoughts on the better of _SERVER["HTTP_HOST"] or _SERVER["SERVER_NAME"] to use when building things like a "page-stamp" in a footer, i.e., showing the user the URL of the page they're actually looking at, on the off-chance that my site gets "framed" in some way (for an example of what I'm talking about, see a page at my site, e.g. http://genes.gilkison.net/ky10cav/dyer.html).

I realize that they both display the same thing at this point (at least they do on my DH setup), but what is the difference supposed to be? I try to build my scripts, such as they are, defensively, and these things seem to change occasionally from one version of PHP to another, so I'd like ot try and use the appropriate one...

Re: PHP: HTTP_HOST vs. SERVER_NAME

Posted by: atacama
Posted on: 2003-02-04 15:55:00

This just came up on a mailing list I subscribe to. The person posting on that list recommended using HTTP_HOST, and falling back on SERVER_NAME only if HTTP_HOST was not set. He said that SERVER_NAME could be unreliable on the server for a variety of reasons, including:
* no DNS support
* misconfigured
* behind load balancing software

The original post was in the context of the source code for an application that other list subscribers would be installing on a wide variety of servers. I'm not sure how this relates to your situation, but I thought I would pass on the info in case you might find it useful.

Tags: server namephpoccasionallyhttpfooterguruscriptsurlhtml