One of the most important things when driving all types of traffic to a landing page, is to redirect them to an appropriate offer that is suitable for that visitors country. For example, If you are driving Facebook “Fan Page” traffic. Then the visitors will be from all different countries. If you send them direct to a USA only offer, More then likely, you will lose all those visitors from UK, CAN, AUS and every other country. For some reason, people think that the network will look after you and redirect the user to a similar offer. But often this isn’t the case. All in all, it’s all about squeezing every possible chance of making money from those visitors that otherwise, would be wasted.
First thing you will need to do is find a Geo IP database. The best free one out there (Actually possible the only one out there that I know of), is from MaxMind. You can download from here : http://www.maxmind.com/app/geoip_country.
Be sure to download the “CSV” format. This is required so we can load it into a SQL database. For this tutorial, I’ll be using MYSQL. Although preferably I would do it in MSSQL, MYSQL comes with almost every cpanel hosting on the web.
Create a new database on your hosting through CPanel, and then go to PHPMyAdmin. If you don’t know how to do these things, just look them up through Google.
Once inside PHPMyAdmin, You will need to create a new Table on the database you just created. You can do this using the GUI or use the following script file. Once again if you are struggling with this, just read up about it on Google
So here is the code to create the database :
CREATE TABLE IF NOT EXISTS `IPCountries` (
`IP_START` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`IP_END` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`IP_FROM` double NOT NULL,
`IP_TO` double NOT NULL,
`COUNTRY_CODE2` char(2) COLLATE utf8_unicode_ci NOT NULL,
`COUNTRY_NAME` varchar(50) COLLATE utf8_unicode_ci NOT NULL
)
Ofcourse you can use the GUI aswell if you know what you are doing.
Once you have your table, Select it, then go to the “Import” tab. From here you can import the CSV Geo IP database. The settings you need are :
- Format as CSV
- Fields Terminated By ,
- Fields Enclosed By ”
- Lined Terminated By \n
The rest you don’t need to worry about. Select your CSV file and click “Go”. The process takes forever, especially on a slow connection because the CSV file is actually fairly large. Especially for an Upload.
Although, I can’t say I’m a big fan of the way the Table is set out (No Keys, Indexes, Id’s etc), It does work for the most part.
From PHP code all you need to do is write queries similar to below :
<?php
$DatabaseServer = “localhost”;
$Username = “Username”;
$Password = “Password”;
$DatabaseName = “Database”;$link = mysql_connect($DatabaseServer, $Username, $Password, TRUE) or die(‘Could not connect: ‘ . mysql_error());
mysql_select_db($DatabaseName, $link) or die(‘Could not select database’);function GetCountryCode()
{
$IP = $_SERVER["REMOTE_ADDR"]; //Get the IP address
$res = mysql_query(“SELECT country_code2,country_name FROM databasename.IPCountries WHERE IP_FROM<=inet_aton(‘$IP’) AND IP_TO>=inet_aton(‘$IP’)”);//look up IP address$Codes = mysql_fetch_array($res); //get result
$Country = $Codes['country_code2']; //two-letter country codereturn $Country;
}$countryCode = GetCountryCode();
if($countryCode == “US”)//If user is from USA
{
//Do something here. Redirect/Show Banner
}
else
if($countryCode == “CA”)//Else if user is from Canada
{
//Do something here. Redirect/Show Banner
}
It all seems a bit confusing because i have this all separated out into their own files, Hence the function in the middle of the file etc. But this WILL work.
Once you know the users country, You can either redirect them, show a different landing page then the rest, even show a banner. I have this working on one of my sites to show them relevant ads. Hell, really you can do anything with this code. I’ve seen people use the exact same code to run PTC sites.
Something I forgot to mention above, Maxmind database isn’t 100% accurate. More like 98%. You seriously won’t find anything else that comes close to being as good, and for free aswell.


The best “non-free” database is Digital Envoy’s NetAcuity product. I used to work for a major ad network and this is the IP database that most ad networks use for targeting. To be consistent with what they’re doing you may want to try that: http://www.digitalenvoy.net
Maxmind is a very good database for a free database. Digital Envoy is more accurate overall and has some bells and whistles.