Possible Duplicate:
HTTP_HOST vs. SERVER_NAME
What is the difference between $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME'] ??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$_SERVER['SERVER_NAME']gives the value of the server name as defined in host configuration (i.e for Apache the Apache.conffile).$_SERVER['HTTP_HOST']gives you the domain name through which the current request is being fulfilled and is more directly related to the request.HTTP_HOSTis typically more useful in most applications in that it relates directly to the request, whereasSERVER_NAMEcould return whatever value is in the conf file and doesn’t tell you anything about the request at all.I will give you an example of how
HTTP_HOSTmight differ fromSERVER_NAME. Say you have an host defined in Apache with ServerName ofexample.comand an IP address of1.2.3.4.Let’s look at two incoming request URLs and show the difference between these variables:
So again, HTTP_HOST is tied more to the request, whereas SERVER_NAME is determined by server configuration.