• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
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
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


behind load balancing software

Related questions

0 votes
asked Jun 6, 2020 in PHP by SakshiSharma
0 votes
asked Jun 4, 2020 in PHP by Robindeniel