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) & "
See also  How College Students Can Shape the Future of Tech Responsibility

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist

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