
Redirecting Users based on User's Country!
Ok, so, just to let you know, this is how I did it:
I don't really have ANY experience with PHP, but I started searching everywhere to find a solution. And this seems to have worked:
First, I downloaded MaxMind's GeoIP.dat database from here:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz Free Version (GeoLiteCountry)
Then I downloaded geoip.inc from here:
http://geolite.maxmind.com/download/.../php/geoip.inc
Then I uploaded those two files to the same directory where my page is located.
I edited my php page and wrote this script inside of it
Always make sure to update the GeoLite databases once every month or so.
Here it goes:
<?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://USSite.com');
}
elseif($country_code == 'CA')
{
header('Location: http://CanadaSite.com');
}
elseif($country_code == 'ES')
{
header('Location: http://SpainSite.com');
}
else {
header('Location: http://AllSite.com');
}
?>
<?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')
{
?> HTML Code US <?php;
}
elseif($country_code == 'CA')
{
?> HTML Code CA <?php;
}
elseif($country_code == 'ES')
{
?> IFRAME SPAIN <?php;
}
else {
header('Location: http://AllSite.com');
}
?>
Country Codes can be found here: MaxMind - ISO 3166 Country Codes
Woalah!
Hope this helps!

-
cevin -
Thanks
SignatureService computer at AthensPC. Fast laptop repair, qualified technicians, technical support via internet and online computer lessons.{{ DiscussionBoard.errors[3286085].message }} -
-
PabloVTB -
Thanks - 1 reply
SignatureATTENTION! {{ DiscussionBoard.errors[3292211].message }}-
kidpunky -
Thanks
{{ DiscussionBoard.errors[4627098].message }} -
-
-
Snatch -
Thanks
{{ DiscussionBoard.errors[4794725].message }} -