Difference b/w SERVER_NAME and HTTP_HOST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Difference b/w SERVER_NAME and HTTP_HOST

Post by anjanesh »

What difference can there be between $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST'] ?

Both are always rerturning the same values. Which is the one to determine subdomains ? Both are showing the correct sub-domain.

Thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

'SERVER_NAME'
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

'HTTP_HOST'
Contents of the Host: header from the current request, if there is one.



My guess (not sure, should give it a try) is that if you have for example
<VirtualHost 127.0.0.1>
ServerName test
Alias tester
</Virtualhost>

And you surf to http://tester

$_SERVER['SERVER_NAME'] => test
$_SERVER['HTTP_HOST'] => tester
Post Reply