The web has no national boundaries, and most websites will attract visitors from all around the globe.
I needed to be able to determine the country location of each visitor to a site. Although you can never expect to achieve a 100% correct answer, you can get close.
A client of mine wanted to provide an free incentive for every visitor who landed on a particular page of his site. He knew from his web stats that at least 80% of site visitors were non UK. As all his business, video production, was UK based, he didn't want the expense of providing the free CD showreel to overseas visitors.
I needed a database that maps IP addresses to a country. There are several sources to choose from, I used IP2Location which costs $49 and includes free updates for a year. Data is provided in Access, CSV and MySQL formats. This how the first few rows of the data looks
| ipFROM | ipTO | countrySHORT |
| 0 | 33996343 | - |
| 33996344 | 33996351 | UK |
| 33996352 | 50331647 | - |
| 50331648 | 67277055 | US |
| 67277056 | 67277119 | CA |
The total number records is about 60,000. The database is constantly updated.
I used a Access database on the server as it was simple to use, there was no setup unlike SQL server and with less than 100 visitors per day there was no performance concerns.
The code, written in VB ASP, used ADO to perform the database lookup. Here is the code I use
' This sample code is provided as is,
for aiding understanding. ' Set IP string, 1st check for proxy set oConnIP = CreateObject("ADODB.Connection") nIP = Dot2LongIP(sIP) function Dot2LongIP (ByVal DottedIP) if len(DottedIP) < 7 or isnull(DottedIP) or DottedIP =
"unknown" then |
There are many other reasons why you might it is useful to determine the country location of your site visitor:
Web log statistics and analysis
Providing localised contact information
Help identify possible credit card fraud
| Copyright © 2006 Paul Stanley Software | 7 Needham Way, Skelmersdale, Lancashire, WN8 6PR 01695 720562 | info@pssuk.com |
Bespoke Software Development - Custom database & web business applications developer Lancashire North West, NW UK
Manchester, Liverpool, Warrington, St Helens, Southport, Preston, Blackburn, Bolton, Blackpool, Lancaster, Skelmersdale, Runcorn
Web Applications
Uses
Advantages
Examples
Employee Wellbeing
VDU Risk Assesment
Press Office
Bespoke Estimating Software
Warehouse Despatch
Websites
Website Production
Website Examples
A-Z of Web Terms
Contribute