HTTP_HOST:從客戶端請求獲取的HTTP請求頭中獲取
例子:
Website: https://www.geeksforgeeks.org HTTP_HOST: www.geeksforgeeks.org
HTTP_SERVER:根據主機配置從服務器名稱中獲取。
例子:
Website: https://www.geeksforgeeks.org HTTP_SERVER: Display the server name
HTTP_HOST | SERVER_NAME |
---|---|
它從客戶端檢索請求標頭。 | 它檢索服務器配置。 |
它不可靠,因為它的值可以修改。 | 它更可靠,因為它的值來自服務器配置。 |
語法:$_SERVER[‘HTTP_HOST’] | 語法:$_SERVER[‘SERVER_NAME’] |
它給出了滿足請求的主機的域名。 | 它給出主機配置中指定的服務器名稱。 |
示例:本地主機:8080 | 示例:www.google.com |
它基於客戶的要求。 | 它基於 Web 服務器的配置。 |
由於它與請求直接相關,因此在大多數應用程序中都使用它。 | 它根本不提供有關請求的任何信息。 |
它是從目標主機獲取的。 | 它取自服務器配置。 |
這是客戶控製的值。 | 這是服務器控製的值 |
http://www.google.com HTTP_HOST:www.google.com |
http://www.google.com HTTP_SERVER:google.com |
HTTP_HOST 示例:
<?php
echo $_SERVER['HTTP_HOST'];
?>
輸出:
It display the host name.
HTTP_SERVER 示例:
<?php
echo $_SERVER['SERVER_NAME'];
?>
輸出:
It display the server name.
注意:如果是本地主機,主機名和服務器名都相同。
相關用法
- PHP Hebrev()用法及代碼示例
- PHP Max()用法及代碼示例
- PHP String htmlspecialchars()用法及代碼示例
- PHP String htmlspecialchars_decode()用法及代碼示例
- PHP String localeconv()用法及代碼示例
- PHP String nl2br()用法及代碼示例
- PHP String nl_langinfo()用法及代碼示例
- PHP String quoted_printable_decode()用法及代碼示例
- PHP String quoted_printable_encode()用法及代碼示例
- PHP String sprintf()用法及代碼示例
- PHP String sscanf()用法及代碼示例
- PHP String str_replace()用法及代碼示例
- PHP String strrpos()用法及代碼示例
- PHP String strspn()用法及代碼示例
- PHP String strstr()用法及代碼示例
- PHP String strtok()用法及代碼示例
- PHP String strtolower()用法及代碼示例
- PHP String strtoupper()用法及代碼示例
- PHP String strtr()用法及代碼示例
- PHP String substr()用法及代碼示例
- PHP String substr_compare()用法及代碼示例
- PHP String substr_count()用法及代碼示例
- PHP String substr_replace()用法及代碼示例
- PHP String ucfirst()用法及代碼示例
- PHP String ucwords()用法及代碼示例
注:本文由純淨天空篩選整理自vaishali bhatia大神的英文原創作品 What is the difference between HTTP_HOST and SERVER_NAME in PHP?。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。