Redirecting Users based on Different Countries - Cyber Tweaks

Ads Top

Redirecting Users based on Different Countries

Redirect user to his country php script

Sometimes you need to redirect visitors based on the country they come from. Maxmind provides a great country/IP address database in binary format. The following example will show you how redirect visitors from countries which are not on the "whitelist".

This script is useful in many ways. if you are working on Affiliate networks then you can use it to redirect your users to different offers according to his country.

You required to upload total 3 files.

First, download MaxMind's GeoIP.dat database from here:

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

Second, Download geoip.inc from here:

http://www.mediafire.com/?2w4jo2ydbywa675

Third, create redirect.php check this PHP code

<?php
require_once("geoip.inc");

$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);

$country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

if($country_code == 'US') 
{
        header('Location: http://google.us');
}
elseif($country_code == 'CA')
{
        header('Location: http://facebook.com');
}
elseif($country_code == 'ES')
{
        header('Location: http://google.es');
}
else {
        header('Location: http://google.com');
}
?>

Find out country codes from here : http://www.maxmind.com/en/iso3166

Download full source with samples from here : http://www.mediafire.com/?04m0ymk6cnwbyim

No comments:

Powered by Blogger.