WebBuilder101 - Making the web happen!
Need Web Dev software? Here is the place to
Flash Point

By: Hexa Software Development Center
Knowledge Service Group

Redirect Web Visitors By Country Using ASP and COM Technology

There are times when it is useful to redirect a visitor to different default web pages based on the visitor's country of origin. One practical usage is to redirect the visitor to a web page with language recognized by the visitor. This article shows you how this can be done with ASP and ActiveX components. [editet by WB101]

Let us take a simple case study. Company XYZ is multi-national company with major customers from United States and Japan. The company official website is developed in both English and Japanese languages. The default page is in English language and visitor can switch to Japanese by changing the default language option. There exists a potential problem when a Japanese visitor does not understand English and it could not navigate the web site. So let us developed a simple solution to help Company XYZ redirecting all Internet traffic from country Japan to the Japanese language site. Meanwhile it drives the rest traffic to English site.

In this example, we use a fully functional IP2Location™ ActiveX component available at http://www.ip2location.com/ip2location-country.zip [external link] to query country by visitor's IP address. For unregistered component, there is a 5-second delay in every query. First, install the ActiveX component in IIS web server. It could be as simple as running a command in DOS prompt. 

        C:\> regsvr32 ip2location.dll 


Let's assume the English web page as index_en.htm and Japanese web page as index_jp.htm. We implement a simple script default.asp to detect visitor's country of origin. If the visitor is from Japan, then redirect him/her to index_jp.htm, otherwise index_en.htm. Simple? Here is the code and the comments serve as explanation default.asp.

<%
    ' Create server-side object
    Set ipObj = Server.CreateObject("IP2Location.Country")

    ' Initialize IP2Location object
    If ipObj.Initialize("demo") <> "OK" Then
        response.write "IP2Location Initialization Failed.
    End If

    ' Get visitor's IP address
    IPaddr = Request.ServerVariables("REMOTE_ADDR")

    ' Detect visitor's country of origin by IP address
    CountryName = ipObj.LookUpShortName(IPaddr)

    ' Free IP2Location object 
    Set ipObj = nothing

    If CountryName = "JP" Then
        ' Visitor is from Japan
        ' Redirect the URL to index_jp.htm
        Response.Redirect "index_jp.htm"
    Else
        ' Visitor is not from Japan
        ' Redirect the URL to index_en.htm
        Response.Redirect "index_en.htm"
    End If
%>

Place this script as the default script of the web site. All visitors will go through this screening before redirect to an appropriate web page.

----------------------------------------------------------------------------------------------------

This article was contributed by:
Hexa Software Development Center
Knowledge Service Group
NP 3D-12-05, Jalan Batu Uban,
11700 Gelugor,
Pulau Pinang, Malaysia.
{ sales@ip2location.com }

.

 

More Resources
How to Promote your site
A quick guide to having a web presence

Suggested Reading

Beginning Active Server Pages 3.0
JavaScript Bible
Red Hat Linux
Dreamweaver 3.0
HTML Bible



Download WB101 Wallpaper
• Web Builder 101 Wallpaper Get it!.
• Find out how to create your own Wallpaper Teach me!.
Sign up for our Newsletters
• Web Building Sign me Up!.
• Net Alert! Sign me Up!.
Need Help?
• Contact Support Click here.
• E-mail the Webmaster Click Here.
• Search Tips Click Here.

Webbuilder101.com © 1998 - 2003 Copyright and Terms of Use
Send mail to: webmaster@webbuilder101.com

» About » Support

» FAQ » What's New » MyLog

Web Builder 101 Web Builder 101 - Making the Web Happen Web Builder 101 - Making the Web Happen
.