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

Related questions

+1 vote
asked May 11, 2022 in PHP by sharadyadav1986
+1 vote
asked Jun 23, 2019 in PHP by SakshiSharma
+1 vote
asked May 13, 2022 in PHP by john ganales
...