在 HTTP 協定(RFC2612) 中提到, Host 可用於得知使用者存取主機資源時會使用的主機名稱,供 HTTP Server 判斷虛擬主機設置。Accept-Language 可用於得知使用者的地區語文清單。服務者可根據此清單內容,呈現最適用於使用者的地區語文內容。
在 PHP 中,可藉由全域變數 $_SERVER['HTTP_HOST'] 、 $_SERVER['SERVER_NAME'] 取得 Host 內容。$_SERVER['HTTP_ACCEPT_LANGUAGE'] 取得瀏覽器適用的語文清單。
HTTP_HOST, SERVER_NAME should be the same. However, SERVER_NAME looks like only available in Apache2.
14.23 Host
Host = "Host" ":" host [ ":" port ] ; Section 3.2.2
A “host” without any trailing port information implies the default port for the service requested (e.g., “80” for an HTTP URL). For example, a request on the origin server for would properly include:
GET /pub/WWW/ HTTP/1.1
Host: www.w3.org
14.4 Accept-Language
The Accept-Language request-header field is similar to Accept, but restricts the set of natural languages that are preferred as a response to the request. Language tags are defined in section 3.10.
Accept-Language = "Accept-Language" ":"
1#( language-range [ ";" "q" "=" qvalue ] )
language-range = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
Each language-range MAY be given an associated quality value which represents an estimate of the user's preference for the languages specified by that range. The quality value defaults to “q=1”. For example,
Accept-Language: da, en-gb;q=0.8, en;q=0.7
地區語文清單的代碼係根據 ISO 3316 language code 。
- 台灣地區之語文代碼為: zh-tw
- 中國大陸地區之語文代碼為: zh-cn
- 中文語文代碼為: zh
See also: PHP Manual:Predefined Variables