Home > Paid Traffic Sources > Mobile

mobile geo country redirect script (3)


04-20-2012 07:06 PM #1 mwhiz (Member)
mobile geo country redirect script

Does anyone have a mobile geo script that will redirect visitors to different URLs based on country?

I seem to remember someone posting this in a thread, however, I couldn't find it.

I got the following script from somewhere, but I'm getting several errors whenever I try to use it:

<?php


$referrer = $_SERVER['HTTP_REFERER'];
$ipx = $_SERVER['REMOTE_ADDR'];
$timex = date("d/m/y : H:i:s", time()) ;
$fp = fopen ($filename, "a");
fwrite ($fp, "$fline\n");
fclose ($fp);

$url_US = "http://xxx.com";
$url_UK = "http://xxx.com";
$url_DE = "http://xxx.com";
$url_AU = "http://xxx.com";
$url_CA = "http://xxx.com";
$url_ELSE = "http://xxx.com";
$url_ELSE1 = "http://xxx.com";

include("geoip.inc");

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

$ip = $_SERVER['REMOTE_ADDR'];

$cont = geoip_country_code_by_addr($gi, "$ip");

geoip_close($gi);

if (preg_match("/US/", "$cont")) {

header("location: $url_US");

} elseif(preg_match("/GB/", "$cont")) {

header("location: $url_UK");

} elseif(preg_match("/AU/", "$cont")) {

header("location: $url_AU");

} elseif(preg_match("/DE/", "$cont")) {

header("location: $url_DE");

} elseif(preg_match("/CA/", "$cont")) {

header("location: $url_CA");

} elseif(preg_match("/(NZ|NO|FR|SE|IT|CH|NL|AE|IE|BE|ES|AT|IS|IL|ZA)/", "$cont")) {

header("location: $url_ELSE1");

}else{

header("location: $url_ELSE");
}

?>

Does anyone have a good, working script?

Has anyone tried using the above script?


04-20-2012 09:41 PM #2 zeno (Administrator)

I was under the impression the problem is there are no accurate IP databases for mobile, so geo-redirection based on IP is currently mediocre at best.


04-21-2012 01:11 AM #3 leber026 (Member)

That script will not work unless you also have the geoip.inc and GeoIP.dat files. Check Maxmind.com for those files. This page should be a good start http://www.maxmind.com/app/geolitecountry


Home > Paid Traffic Sources > Mobile