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:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

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