📜  PHP的HTTP_HOST 和 SERVER_NAME 有什么区别?

📅  最后修改于: 2022-05-13 01:54:10.993000             🧑  作者: Mango

PHP的HTTP_HOST 和 SERVER_NAME 有什么区别?

HTTP_HOST:从客户端请求获取的HTTP请求头中获取

例子:

Website: http://www.geeksforgeeks.org
HTTP_HOST: www.geeksforgeeks.org

HTTP_SERVER:根据主机配置从服务器名称中获取。

例子:

Website: http://www.geeksforgeeks.org
HTTP_SERVER: Display the server name
HTTP_HOSTSERVER_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:8080Example: 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

HTTP_HOST 示例:




输出:

It display the host name.

HTTP_SERVER 示例:


输出:

It display the server name.

注意:如果是 localhost,HOST 和 SERVER 名称都将相同。