Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Server Variables: Popular Ones
     [next Lesson]  Server Variables: Displaying All

Server Variables To Determine Domain

Server Variables have many uses. We will show you a popular one here. Web sites are typically attached to an IP address, but sometimes several domain names may point to the same IP. A clever ASP script could display the same page different ways depending on which domain name was typed utilizing the HTTP_HOST. Our site, for example has three domain names tied to the same IP ( activeserverpages.com, asptraining.com, learnasp.com, help.activeserverpages.com ) and the following script will provide different results depending on what domain name it is called from:

   filename=/learn/test/server2.asp

<Test Script Below>


<html><head>
<title>server2.asp</title></head>
<body>
<%
host=lcase(request.servervariables("HTTP_HOST"))
SELECT CASE host
    CASE "www.asptraining.com"
        response.write "Welcome Training Customer!"
    CASE "www.activeserverpages.com"
        response.write "Welcome To Our Reference Site!"
    CASE "www.learnasp.com"
        response.write "Welcome To Our Tutorial!"
    CASE "www.aspeuro.com"
        response.write "Welcome To Our European Site!"
    CASE "www.asplists.com","www.asplist.com"
        response.write "Welcome To Our ASP listservers!"
    CASE "www.aspconventions.com","www.aspconvention.com"
        response.write "Welcome To Our ASP convention site!"
    CASE ELSE
        response.write "Welcome!"
END SELECT
%>
</body></html>

Did this site teach you to code?   THANK US here!.   Your gift is NOT tax deductible, but I am very grateful. 2004 gift gallery & 2005 gift gallery