Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web Development
Expertise: Beginner
Jul 1, 1999



Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js

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 ""
Name Value
" & x & "" & Request.ServerVariables(x) & "
DevX Pro
Submit a Tip Browse "Application Design" Tips Browse All Tips
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date