The major difference between the two is that $_SERVER['SERVER_NAME']
is a server controlled variable, while $_SERVER['HTTP_HOST']
is a user-controlled value.
The rule of thumb is to never trust values from the user, so $_SERVER['SERVER_NAME']
is the better choice.
As Gumbo pointed out, Apache will construct SERVER_NAME from user-supplied values if you don't set UseCanonicalName On
.
Edit: Having said all that, if the site is using a name-based virtual host, the HTTP Host header is the only way to reach sites that aren't the default site.