The ASP ServerVariables Collection retrieves the values of predetermined environment variables and requests header information.

The ASP ServerVariables collection can provide you with quite a bit of information found in the headers such as IP addresses, server name, virtual path, request method, etc.

It is a common approach to use the ServerVariables collection to obtain your visitors’ IP address, user agent (browser) info, etc. The list of ServerVariables will depend on the server software and on the browser being used.

Syntax

Request.ServerVariables (SERVER_VARIABLE)

Example

In this example, you can use the Response.Write method in conjunction with a For..Next loop to enumerate the ServerVariables Collection

Server Variables

<% Response.Write("

")

For Each x In Request.ServerVariables Response.Write("

") Response.Write("”) Response.Write("") Next

Response.Write("

" & x & “” & Request.ServerVariables(x) & “
") %>

The following is a listing of the server variables that can be accessed in the ASP ServerVariables Collection.

In the case where you only need to retrieve one server_variable, you could do so by using the Request.ServerVariables collections.

<% Response.Write(Request.ServerVariables(“REMOTE_ADDR”)) %>