GeoIP - Where are your internet visitors coming from?






4.82/5 (17 votes)
Nov 29, 2002
1 min read

279979

3256
Where are your internet visitors coming from?
Introduction
With GeoIP you can detect where your visitors are coming from. You can use this information to deliver personalized information (see image below), reducing credit card fraud, analyzing web server logs (I use it for SNIFF), target banner ads, .... (see Solutions at MaxMind - http://www.maxmind.com/)
Note
If you can install a component on your web server, you should download the GeoIP component from MaxMind . I wrote GeoIP.asp since my provider doesn't allow me to install components.
Prerequisite
(Updated 1.sep.03, new urls) You need the GeoIP database - http://www.maxmind.com/app/standard, and you need ADO 2.5 or later since GeoIP.asp uses the ADO Stream object to read the GeoIP database.
Installation
- Download the GeoIP.dat database from MaxMind
http://www.maxmind.com/app/standard - Put GeoIP.asp, example.asp and GeoIP.dat in a catalog on your web server.
- Test the installation by accessing the example.asp page
http://yourserver/path/example.asp
Methods and Properties
GeoIP.asp exposes these public methods and properties
Properties
GeoIPDataBase
- Sets the path and filename to GeoIP.datErrNum
- Returns the error number (if <> 0, there's an error)
Methods
lookupCountryName
- Find an IP's country name- example:
strCountryName = oGeoIP.lookupCountryName(strIP)
lookupCountryCode
- Find an IP's country code- example:
strCountryCode = oGeoIP.lookupCountryCode(strIP)
Using the code
It's rather simple to use this code:
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode
Set oGeoIP = New CountryLookup
oGeoIP.GeoIPDataBase = Server.MapPath("GeoIP.dat")
If oGeoIP.ErrNum(strErrMsg) <> 0 Then
Response.Write(strErrMsg)
Else
strIP = request.ServerVariables("REMOTE_ADDR")
strCountryName = oGeoIP.lookupCountryName(strIP)
strCountryCode = oGeoIP.lookupCountryCode(strIP)
End If
Set oGeoIP = Nothing
%>
Have fun coding, Per