What is the difference between HTTP_HOST and SERVER_NAME in PHP

藏色散人
Release: 2023-04-05 10:52:01
Original
3844 people have browsed it



What is the difference between HTTP_HOST and SERVER_NAME in PHP

##HTTP_HOST: Obtained from client request Obtain

from the HTTP request header. Example:

网站: http://www.php.cn
HTTP_HOST: www.php.cn
Copy after login

HTTP_SERVER: Obtained from the server name according to the host configuration.

Example:

网站: http://www.php.cn
HTTP_SERVER: Display the server name
Copy after login

##SERVER_NAMEIt retrieves request headers from the client. It is unreliable because its value can be modified. Syntax: $ _SERVER ['HTTP_HOST'] It provides The domain name of the host that satisfies the request. Example: localhost:8080It is based on the customer's requirement. Because it is directly related to the request, it is used in most applications. It is taken from the target host. It is a value controlled by the customer. http://www.php.cn HTTP_HOST:www.php.cn http://www.php.cn ##HTTP_HOST Example:
HTTP_HOST
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[&#39;HTTP_HOST&#39;];  
?>
Copy after login
Output:
// 它显示主机名
Copy after login

Example of HTTP_SERVER:

<?php 
echo $_SERVER[&#39;SERVER_NAME&#39;]; 
?>
Copy after login
Output:
//它显示服务器名称
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template