Determine Server With ServerVariables

Determine Server With ServerVariables


We have users coming into our homepage from two different servers. I would like to differentiate what gets shown (text, links, and so forth) based on the server that the user is coming through. Is it possible to identify what server is being used when the data is being accessed, and can you then conditionally show or not show data based on that information?


If your servers use Active Server Pages (ASP) you can determine the name of the server from which the page comes with ServerVariables.Request.ServerVariables(“HTTP_HOST”) will return the name of the Web server. You can then use that return value in an “If” statement to determine which HTML to show. For example:

<%If UCASE(Request.ServerVariables("HTTP_HOST")) = "SERVER1" Then%>

Show plain HTML


Show italicized HTML

<%end if%>

Note that I have wrapped the call to the ServerVariables in a UCASE() method. This is to ensure that the comparison will work regardless of uppercase or lowercase letters in the server name. Using the name of the server and the “If” statement, you can control which section of HTML gets written to the page, and which doesn’t.

As a bonus, here is some code that you may find useful. This code will display all of the ServerVariables and their values in a nice table. This demonstrates the types of information that you can retrieve from ServerVariables.

<%For Each x in Request.ServerVariables 	Response.Write ""Next%>
" & x & "" & Request.ServerVariables(x) & "
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

©2023 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.