Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get domain name [duplicate]

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?

Thank you.

like image 468
Francisc Avatar asked Mar 23 '11 11:03

Francisc


1 Answers

Similar question has been asked in stackoverflow before.

See here: PHP $_SERVER['HTTP_HOST'] vs. $_SERVER['SERVER_NAME'], am I understanding the man pages correctly?

Also see this article: http://shiflett.org/blog/2006/mar/server-name-versus-http-host

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

Source: http://discussion.dreamhost.com/thread-4388.html

like image 107
Mukesh Chapagain Avatar answered Sep 22 '22 11:09

Mukesh Chapagain