Wednesday, November 18, 2009

Display Advertisement by Country using ASP and COM Technology

IP2Location™ ActiveX/COM DLL
Online advertisements these days are now raking in the big bucks due to the simple fact that it is now possible to display different advertisements to web visitors from different countries. By showing an advertisement that is relevant to the web visitor, there is a higher chance that it will attract the attention of the web visitor which tends to lead to a sale.

In this example, we use a fully functional IP2Location™ActiveX component available at to determine the visitor’s country by their IP address. Since the component is unregistered, there is a 5-second delay in every query.

To avoid any delays in the query, you can consider purchasing the IP2Location ActiveX/COM Component Version 3.0, which is a software development component and data solution for Windows®. You can tailor the content of your site dynamically based on visitor’s country, region, city, latitude, longitude, ZIP code, ISP, domain name, time zone, connection speed, IDD code, area code, weather station code and weather station name.

Copy the ActiveX component to the IIS web server. Then run the following command in DOS prompt.

C:\> regsvr32 ip2location.dll

Below is the sample code in ASP which will display advertisement by country.

<% ' 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
' Show advertisement from Japan
response.write "<img src=""Japan.jpg"" border=""0"" height=""200"" width=""100"">"
' Visitor is not from Japan
' Show other advertisement
response.write "<img src=""US.jpg"" border=""0"" height=""200"" width=""100"">"
End If

IP2Location also carries a wide variety of databases which are more advanced and has more types of data which could also be used to further narrow down your target audience. If you want to try out the online demo, you can go to and check it out.