mointernet
Regular Member
- Apr 21, 2008
- 442
- 213
This is the non-javascript version of the GeoIP redirect script and I take no credit for the codes below as I believed similar script were posted very long ago but you know peeps here do not search that far back so I hope this will help some people here. I personally run thousands of traffic daily thru this script using media buys with no problems, the only maintenance you need is to manually update the Maxmind database file monthly and of course edit the country codes to your traffic requirements.
The advantage of using this here other than for the purpose of redirecting traffic according to country codes, this script uses php codes (non JS) and read its database through a flat file database (no mySQL) available for free and you can update it monthly (Maxmind website). Not only its fast and its pretty accurate.
copy & save (edit and add country codes where necessary) this code as a geoip.php file. note: The default line should be there all times as it redirect all else traffic
download & unzip the GeoIP.dat file from the URL (you should manually update this monthly for accuracy).
unzip geoip.zip (attachment) and place geoip.inc, GeoIP.dat and geoip.php together and send your traffic through the geoip.php file. **You may rename geoip.php to whatever filename you like.
The advantage of using this here other than for the purpose of redirecting traffic according to country codes, this script uses php codes (non JS) and read its database through a flat file database (no mySQL) available for free and you can update it monthly (Maxmind website). Not only its fast and its pretty accurate.
copy & save (edit and add country codes where necessary) this code as a geoip.php file. note: The default line should be there all times as it redirect all else traffic
Code:
<?php
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, "$ip");
// Country name is not used so commented
// Get Country Name based on source IP
//$country = geoip_country_name_by_addr($gi, "$ip");
geoip_close($gi);
switch($country_code)
{
case "US": header("Location: http://yourUSAofferURL.com"); break;
case "CA": header("Location: http://yourCAofferURL.com"); break;
case "GB": header("Location: http://yourUKofferURL.com"); break;
default: header("Location: http://yourINTLofferURL.com");
}
?>
download & unzip the GeoIP.dat file from the URL (you should manually update this monthly for accuracy).
Code:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/
unzip geoip.zip (attachment) and place geoip.inc, GeoIP.dat and geoip.php together and send your traffic through the geoip.php file. **You may rename geoip.php to whatever filename you like.