5 replies
I need to redirect my traffic by visitors country. I have one method for doing this but the code is not what i exactly need.

Im using this code:

Code:
<?php
require_once('geoip.inc');

$gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

$my_countries = array('us', 'ca', 'gb', 'fr', 'de', 'nl');
if (!in_array(strtolower($country), $my_countries))
{
header('Location: http://www."ALL"TRAFFICURLGOESHERE.whatever');
}
else
{
header('Location: http://www."SELECTEDCOUNTRIES"URLGOESHERE.whatever');
}
?>
...and Im using these files:

http://geolite.maxmind.com/download/...y/GeoIP.dat.gz

http://geolite.maxmind.com/download/.../php/geoip.inc

It works but only for one group or one country. This script is sending the visitors from selected countries to second url and other IP's to first url.

I need a code that will send different countires to different URL's. I need to set up few countries (one url per country) and one url for other countries, that are not metioned in the code.

For example:

USA -> url1
GB -> url2
CA -> url3
All other countries -> url4

Can anyone help me? I think its simple for advenced coder, but I have 0 experience in PHP. I think that its possible to use these two files with data that Ive metioned.

Help will be much appreciated.
#country #redirect

Trending Topics