您的位置:首页 > 其它

创建动态Web网页需要知道的10个服务器变量(翻译)

2006-12-02 11:17 603 查看



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_AGENTAn 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_ADDRThe 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_ROOTThe 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_SOFTWAREThe 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_STRINGThe 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_METHODThe 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_NAMEThe 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_CHARSETThe character sets the client is able to receive.

Sending page data in a preferred character set.

REMOTE_USERWhen 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身份验证的时候,用于身份验证的用户名。
内容个性化;信任书的验证。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: