HTTP_HOST: It is fetched from HTTP request header obtained from the client request
Example:
Website: https://www.geeksforgeeks.org
HTTP_HOST: www.geeksforgeeks.org
HTTP_SERVER: It is fetched from the server name based on the host configuration.
Example:
Website: https://www.geeksforgeeks.org
HTTP_SERVER: Display the server name
HTTP_HOST |
SERVER_NAME |
It retrieve the request header from the client. |
It retrieve the server configuration. |
It is not reliable since its value can be modified. |
It is more reliable as its value comes from server configuration. |
Syntax: $_SERVER[‘HTTP_HOST’] |
Syntax: $_SERVER[‘SERVER_NAME’] |
It gives the domain name of the host where the request is fulfilled. |
It gives the server name specified in host configuration. |
Example: localhost:8080 |
Example: www.google.com |
It is based on request from client. |
It is based on configuration of web server. |
As it is directly related to request so it is used in most of the applications. |
It does not give any information about the request at all. |
It is taken from the target host. |
It is taken from server configuration. |
It is client controlled value. |
It is server controlled value |
http://www.google.com
HTTP_HOST: www.google.com
|
http://www.google.com
HTTP_SERVER: google.com
|
Example of HTTP_HOST:
<?php
echo $_SERVER [ 'HTTP_HOST' ];
?>
|
Output:
It display the host name.
Example of HTTP_SERVER:
<?php
echo $_SERVER [ 'SERVER_NAME' ];
?>
|
Output:
It display the server name.
Note: In case of localhost, HOST and SERVER name both will same.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
06 Sep, 2021
Like Article
Save Article