Login
Remember
Register
Ask a Question
PHP get domain name -how to fix it?
0
votes
asked
Feb 2, 2021
in
PHP
by
SakshiSharma
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?
#php-domain
php
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Feb 2, 2021
by
SakshiSharma
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
...