Resources | ASP | Request.ServerVariables()

Request.ServerVariables():


If your website is being run on a Windows / IIS Server, you can use ASP to gain access to the SERVERVARIABLES of the REQUEST object. The following is a list of all the properties that can be exposed in Request.ServerVariables:


ALL_HTTP <%=Request.ServerVariables("ALL_HTTP")%>
ALL_RAW <%=Request.ServerVariables("ALL_RAW")%>
CONTENT_LENGTH <%=Request.ServerVariables("CONTENT_LENGTH")%>
CONTENT_TYPE <%=Request.ServerVariables("CONTENT_TYPE")%>
QUERY_STRING <%=Request.ServerVariables("QUERY_STRING")%>
SERVER_SOFTWARE <%=Request.ServerVariables("SERVER_SOFTWARE")%>
CONTENT_LENGTH <%=Request.ServerVariables("CONTENT_LENGTH")%>
HTTPS <%=Request.ServerVariables("HTTPS")%>
LOCAL_ADDR <%=Request.ServerVariables("LOCAL_ADDR")%>
HTTPS <%=Request.ServerVariables("HTTPS")%>
PATH_INFO <%=Request.ServerVariables("PATH_INFO")%>
PATH_TRANSLATED <%=Request.ServerVariables("PATH_TRANSLATED")%>
REMOTE_ADDR <%=Request.ServerVariables("REMOTE_ADDR")%>
REMOTE_HOST <%=Request.ServerVariables("REMOTE_HOST")%>
REQUEST_METHOD <%=Request.ServerVariables("REQUEST_METHOD")%>
SERVER_NAME <%=Request.ServerVariables("SERVER_NAME")%>
SERVER_PORT <%=Request.ServerVariables("SERVER_PORT")%>
SERVER_PROTOCOL <%=Request.ServerVariables("SERVER_PROTOCOL")%>
SERVER_SOFTWARE <%=Request.ServerVariables("SERVER_SOFTWARE")%>
HTTP_ACCEPT <%=Request.ServerVariables("HTTP_ACCEPT")%>
HTTP_USER_AGENT <%=Request.ServerVariables("HTTP_USER_AGENT")%>
HTTP_UA_PIXELS <%=Request.ServerVariables("HTTP_UA_PIXELS")%>
HTTP_UA_COLOR <%=Request.ServerVariables("HTTP_UA_COLOR")%>
HTTP_UA_OS <%=Request.ServerVariables("HTTP_UA_OS")%>
HTTP_UA_CPU <%=Request.ServerVariables("HTTP_UA_CPU")%>
HTTP_REFERER <%=Request.ServerVariables("HTTP_REFERER")%>
HTTP_CONNECTION <%=Request.ServerVariables("HTTP_CONNECTION")%>
URL <%=Request.ServerVariables("URL")%>
REMOTE_USER <%=Request.ServerVariables("REMOTE_USER")%>


The following is a brief description of some of these variables (a few of the following variables only work on older versions of IIS, and were thus omitted from the preceding list):

AUTH_TYPE
The authentication method that the server uses to validate users when they attempt to access a protected script.

CONTENT_LENGTH
The length of the content as given by the client.

CONTENT_TYPE
The data type of the content. Used with queries that have attached information, such as the HTTP queries POST and PUT.

GATEWAY_INTERFACE
The revision of the CGI specification used by the server. Format: CGI/revision

HTTP_(HeaderName)
The value stored in the header HeaderName. Any header other than those listed in this table must be prefixed by ?HTTP_? in order for the ServerVariables collection to retrieve its value.

Note: The server interprets any underscore (_) characters in HeaderName as dashes in the actual header. For example if you specify HTTP_MY_HEADER, the server searches for a header sent as MY-HEADER.

LOGON_USER
The Windows NT® account that the user is logged into.

PATH_INFO
Extra path information as given by the client. You can access scripts by using their virtual path and the PATH_INFO server variable. If this information comes from a URL it is decoded by the server before it is passed to the CGI script.

PATH_TRANSLATED
A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping.

QUERY_STRING
Query information stored in the string following the question mark (?) in the HTTP request.

REMOTE_ADDR
The IP address of the remote host making the request.

REMOTE_HOST
The name of the host making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.

REQUEST_METHOD
The method used to make the request. For HTTP, this is GET, HEAD, POST, and so on.

SCRIPT_MAP
Gives the base portion of the URL.

SCRIPT_NAME
A virtual path to the script being executed. This is used for self-referencing URLs.

SERVER_NAME
The server's host name, DNS alias, or IP address as it would appear in self-referencing URLs.

SERVER_PORT
The port number to which the request was sent.

SERVER_PORT_SECURE
A string that contains either 0 or 1. If the request is being handled on the secure port, then this will be 1. Otherwise, it will be 0.

SERVER_PROTOCOL
The name and revision of the request information protocol. Format: protocol/revision

SERVER_SOFTWARE
The name and version of the server software answering the request (and running the gateway). Format: name/version

URL
Gives the base portion of the URL.


Related Links: The Navigator Object


Want to discuss this article, or other development issues? Visit our message boards!

Or contact us directly with a comment or question on this article: click here !
armbrustconsulting.com