創建動態Web網頁需要知道的10個服務器變量(翻譯)

<script language="JavaScript" type="text/javascript"> </script><script language="JavaScript" type="text/javascript"> </script>
advertisement
marginwidth="0" marginheight="0" src="http://ad.doubleclick.net/adi/N1841.cnet.com/B1764282.9;sz=300x250;click0=http://adlog.com.com/adlog/e/r=5152&s=640620&t=2006.12.02.03.05.47&o=29:6371:&h=cn&p=2&b=9&l=en_US&site=14&pt=5100&nd=6371&pid=&cid=6076966&pp=100&e=3&rqid=01c18-ad-e3455B7CDADDAB52D&event=58/;ord=2006.12.02.03.05.47?" frameborder="0" width="300" scrolling="no" height="250" bordercolor="#000000">

Every time you request a Web page, an immense amount of activity takes place behind the scenes: your request is sent to a DNS server, an IP address is found, the corresponding Web server is contacted, and the resulting data stream is decoded and rendered by your Web browser as an HTML page. In addition to the actual HTML content requested, however, the Web server also includes a number of important "server variables" in its response. These variables contain information about both the Web server environment - its name, IP address and software - and the current script execution environment - the script name and path and the query string.

These variables are often used by clever Web developers to make their scripts more dynamic and robust. This document outlines (Table A) some of the more useful server variables that a Web server typically sends out when it responds to an HTTP request, and also explains when and how you could use each one on your Web site.

Note: Some of these variables may not be available in all Web servers.

For more information on these and other server variables, consider taking a look at the CGI 1.1 specification.

Table A


Variable

What It Contains

What It's Useful For

HTTP_USER_AGENT

An identification string sent by the client making the request. For example:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5.

Client detection and logging; creating code that works differently in different browsers.

HTTP_ACCEPT_ENCODING

The list of encodings the client is able to decode.

Improving transfer speeds by using GZIP encoding (for example) to compress page data.

REMOTE_ADDR

The IP address of the client making the request.

Obtaining the user's geographical location for targeted advertising or localized information retrieval; restricting access to specific IP addresses or groups of IP addresses.

DOCUMENT_ROOT

The server's document root directory (as defined in its configuration).

Constructing relative/absolute paths when uploading, copying or moving files through a Web application.

SERVER_SOFTWARE

The server's signature, indicating the name and version of the server as well as any software running on it. For example:

Apache/2.0.55 (Win32).

Identifying server capabilities.

QUERY_STRING

The list of variable-value pairs that follow the "?" in the requested URL.

Retrieving and parsing the variable-value pairs sent to the server via its URL.

REQUEST_METHOD

The method used to make the URL request. For example

GET, POST or PUT.

Identifying the method used to request the page, and thereby accessing the appropriate namespace for variable retrieval.

SCRIPT_NAME

The server path to the requested resource (relative to the document root).

Retrieving the name and path to the currently-executing script or resource.

HTTP_ACCEPT_CHARSET

The character sets the client is able to receive.

Sending page data in a preferred character set.

REMOTE_USER

When using HTTP authentication, the username supplied for authentication.

Content personalization; credential verification.



 

 

 

譯文:

創建動態Web網頁需要知道的10個服務器變量 2006-06-27 09:20 AM

在你每次請求Web頁面的時候,後臺有大量的活動在進行:你的請求被送給一個DNS服務器,IP地址被找到,與相應的Web服務器聯繫,發回的數據流被解碼,再由你的Web瀏覽器生成爲HTML頁面。除了對真正的HTML內容的請求,Web服務器還在其響應中包括了很多重要的“服務器變量”。這些變量含有Web服務器環境的信息——它的名字、IP地址和軟件——以及當前腳本的執行環境——腳本名字和路徑,以及查詢字符串。

這些變量常常被聰明的Web開發人員用來增加腳本動態性和穩定性。表格A裏的文檔簡要列出了10個更加有用的服務器變量,Web服務器在響應HTTP請求的時候一般都會發送這些變量,這個表格還會告訴你何時以及如何在你的Web網站上使用它們。

注:並不是所有的Web服務器上都有這些變量。

要獲得關於這些以及其他服務器變量的更多信息,請參考《CGI 1.1規範》

表格A

在你每次請求Web頁面的時候,後臺有大量的活動在進行:你的請求被送給一個DNS服務器,IP地址被找到,與相應的Web服務器聯繫,發回的數據流被解碼,再由你的Web瀏覽器生成爲HTML頁面。除了對真正的HTML內容的請求,Web服務器還在其響應中包括了很多重要的“服務器變量”。這些變量含有Web服務器環境的信息——它的名字、IP地址和軟件——以及當前腳本的執行環境——腳本名字和路徑,以及查詢字符串。

這些變量常常被聰明的Web開發人員用來增加腳本動態性和穩定性。表格A裏的文檔簡要列出了10個更加有用的服務器變量,Web服務器在響應HTTP請求的時候一般都會發送這些變量,這個表格還會告訴你何時以及如何在你的Web網站上使用它們。

注:並不是所有的Web服務器上都有這些變量。

要獲得關於這些以及其他服務器變量的更多信息,請參考《CGI 1.1規範》

表格A

變量

描述

用途

HTTP_USER_AGENT

發起請求的客戶端所發送的身份字符串。例如:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5。

客戶端的檢測和登錄;創建用於不同瀏覽器的不同代碼。

HTTP_ACCEPT_ENCODING

客戶端能夠解碼的編碼列表。

比如,使用GZIP編碼程序來壓縮頁面數據,以提高傳輸的速度。

REMOTE_ADDR

發送請求的客戶端的IP地址。

獲取用戶的地理位置,用於有針對性的廣告或者本地化信息的取回;限制對特定IP地址或者IP地址羣的訪問。

DOCUMENT_ROOT

服務器文檔的根目錄(在配置文件裏定義)。

在通過Web應用程序上傳、複製或者移動文件的時候創建相對/絕對路徑。

SERVER_SOFTWARE

服務器的簽名,以表明服務器的名字和版本,以及在上面運行的所有軟件。例如:Apache/2.0.55 (Win32)。

能夠識別服務器。

QUERY_STRING

跟在被請求的URL裏“?”之後的變量-值對的列表。

取回或者分析通過URL發送給服務器的變量-值對。

REQUEST_METHOD

這個方法用來進行URL請求。例如:GET, POST or PUT。

識別用來請求頁面的方法,訪問用於變量取回的相應命名空間。

SCRIPT_NAME

被請求資源的服務器路徑(相對於文檔的根目錄)。

取回當前執行的腳本或者資源的名字和路徑。

HTTP_ACCEPT_CHARSET

客戶端能夠收到的字符集。

用首選的字符集發送頁面數據。

REMOTE_USER

在使用HTTP身份驗證的時候,用於身份驗證的用戶名。

內容個性化;信任書的驗證。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章