Hello Reader's!
In working PHP you might have seen the two common syntax $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME']. They share similar name but they work different.
$_SERVER['SERVER_NAME'] gives the value of the server name as defined in host configuration (lets say example Apache the Apache .conf file) and $_SERVER['HTTP_HOST'] gives you the domain name through which the current request is being fulfilled, here user is more related to request.
HTTP_HOST is the header from the current request, if it exists. Whereas SERVER_NAME is the name of the server host under which the current script is executing. If the script is running on a virtual host then this will be the value defined for that virtual host.
Let's see the working example below:-
<?php
echo $_SERVER['SERVER_NAME'];
?>
Output:
www.findnerd.com
And
<?php echo $_SERVER['HTTP_HOST']; ?>
Output:-
localhost:8080
0 Comment(s)