##HTTP_HOST: Obtained from client request Obtain
from the HTTP request header. Example:网站: http://www.php.cn HTTP_HOST: www.php.cn
HTTP_SERVER: Obtained from the server name according to the host configuration.
Example:网站: http://www.php.cn HTTP_SERVER: Display the server name
HTTP_HOST | ##SERVER_NAME|
It retrieves the server configuration. | |
It is more reliable because its value comes from the server configuration. | |
Syntax: $ _SERVER ['SERVER_NAME'] | |
It provides the server name specified in the host configuration. | |
Example:www.google.com | |
It is based on the configuration of the web server. | |
It does not provide any information about the request at all. | |
It is taken from the server configuration. | |
It is a server-controlled value | |
HTTP_SERVER:php.cn |
<?php echo $_SERVER['HTTP_HOST']; ?>
// 它显示主机名
Example of HTTP_SERVER:
<?php echo $_SERVER['SERVER_NAME']; ?>
//它显示服务器名称
Note
: For localhost, HOST and SERVER name are the same.Related recommendations: "PHP Tutorial
"http://www.php.cn/course/list/29.html
The above is the detailed content of What is the difference between HTTP_HOST and SERVER_NAME in PHP. For more information, please follow other related articles on the PHP Chinese website!