0 votes
in PHP by
PHP get domain name -how to fix it?

I want to get the domain name for where the script is running. How can that be done with PHP? I see that $_SERVER['HTTP_HOST'] as well as $_SERVER['SERVER_NAME'] contain this information. Will that variable always work and should I use one over the other?

1 Answer

0 votes
by
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
...