Server Variables Sample

The ASPSmith Articles, ASPAlliance.com

Server Variables Sample

By Steven Smith
http://www.aspalliance.com/stevesmith/articles/servvar.asp
[Example]

The server variables ("ServerVariables") collection can be very helpful when you are developing ASP applications. As you have probably noticed in some of the other sample applications on this site, you can use the server variables collection to determine the client's browser, IP address, the current page they are viewing, the page which referred them to the current page, and many other details. The sample application(code below) listed here is a very simple app which lists all of the server variables and their current values. Note that this information varies depending on what server you are using. IIS4 has many additional variables not included in IIS3. The proper syntax to refer to a server variable in your code is Request.ServerVariables("VariableName").

Below is the source code for the sample application, sv.asp:
   <% OPTION EXPLICIT %>
   <!-- #INCLUDE VIRTUAL="/stevesmith/include/articleformat.asp" -->
   <%
   'Declare Variables
   Dim name
   
   Call ArticleHeader("Server Variables Example","","")
   %>

   <table BORDER>
10   <caption><b>Server Variables:</b></caption>
11   <tr>
12   <td>Variable</td>
13   <td>Value</td>
14   </tr>
15   <%
16   For EACH name IN Request.ServerVariables
17    Response.Write("<TR><TD><B>"&name&"</B></TD>")
18    Response.Write("<TD>" & Request.ServerVariables(name) & "</TD></TR> ")
19   Next
20   %>

21   </table>
22   <%
23   Call ArticleFooter()
24   %>