need go redirect script

pcmoseley

Regular Member
Joined
Mar 13, 2007
Messages
405
Reaction score
128
I really need a simple php or other script to send visitors to a url based on their country code. I found this http://pastebin.com/m923hKz6 but it's not working for me (i'm a noob at coding). I put in my US url and saved it as index.html and index.php but it didn't work
 
here you go, works for me

PHP:
<?php

include("geo/geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("geo/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://offerforusa.com"); break;
        case "CA": header("Location: http://offerforcanada.com"); break;
        case "UK": header("Location: http://offerforuk.com"); break;
        case "AU": header("Location: http://offerforaustralia.com"); break;
        case "NZ": header("Location: http://offerfornewzealand.com"); break;
        default: header("Location: http://offerforothers.com");
}
?>

as you can see, you will need geoip.inc and geoip.dat
you know where to find that

Code:
http://www63.zippyshare.com/v/83299748/file.html

Code:
https://www.virustotal.com/en/file/e6179af4ebe88a223401dfdcc9e5cf24e0d92e42deab513179e48d1eb7489da2/analysis/1373150418/
 
Last edited:
here you go, works for me

PHP:
<?php

include("geo/geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("geo/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://offerforusa.com"); break;
        case "CA": header("Location: http://offerforcanada.com"); break;
        case "UK": header("Location: http://offerforuk.com"); break;
        case "AU": header("Location: http://offerforaustralia.com"); break;
        case "NZ": header("Location: http://offerfornewzealand.com"); break;
        default: header("Location: http://offerforothers.com");
}
?>

as you can see, you will need geoip.inc and geoip.dat
you know where to find that

Code:
http://www63.zippyshare.com/v/83299748/file.html

Code:
https://www.virustotal.com/en/file/e6179af4ebe88a223401dfdcc9e5cf24e0d92e42deab513179e48d1eb7489da2/analysis/1373150418/

I tested your script but it's not working for me. I added geoip.inc and geoip.dat to the main folder and also left it in the geo folder but it's still giving me the same error http://paulmoseley.com/tracking
 
Put geoip.inc and geoip.dat files on subfolder named 'geo' and then try it out.
 
yep, as conzy said geoip.inc and geoip.dat goes in /geo folder

OR

if you want to have geoip.inc and geoip.dat in same folder as index.php, then remove "geo/" on 3rd and 5th line
then your new index.php will be:
PHP:
 <?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://offerforusa.com"); break;
        case "CA": header("Location: http://offerforcanada.com"); break;
        case "UK": header("Location: http://offerforuk.com"); break;
        case "AU": header("Location: http://offerforaustralia.com"); break;
        case "NZ": header("Location: http://offerfornewzealand.com"); break;
        default: header("Location: http://offerforothers.com");
}
?>
 
yep, as conzy said geoip.inc and geoip.dat goes in /geo folder

OR

if you want to have geoip.inc and geoip.dat in same folder as index.php, then remove "geo/" on 3rd and 5th line
then your new index.php will be:
PHP:
 <?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://offerforusa.com"); break;
        case "CA": header("Location: http://offerforcanada.com"); break;
        case "UK": header("Location: http://offerforuk.com"); break;
        case "AU": header("Location: http://offerforaustralia.com"); break;
        case "NZ": header("Location: http://offerfornewzealand.com"); break;
        default: header("Location: http://offerforothers.com");
}
?>

I tried it with the folder but same error..
 
Hello, I havent tested this.. Just something i came up with using the freegeoip API.. Please reply if it's not working..

Code:
<?php
function freegeoip_locate($ip) {
	$url = "http://freegeoip.net/json/" . $ip;
	$geo = json_decode(file_get_contents($url), true);
	return $geo;
}


$geo = freegeoip_locate($_SERVER['REMOTE_ADDR']);
$country_code = $geo['country_code'];


switch($country_code) {
	case "US" :
		header("Location: http://offerforusa.com");
		break;
	case "CA" :
		header("Location: http://offerforcanada.com");
		break;
	case "UK" :
		header("Location: http://offerforuk.com");
		break;
	case "AU" :
		header("Location: http://offerforaustralia.com");
		break;
	case "NZ" :
		header("Location: http://offerfornewzealand.com");
		break;
	default :
		header("Location: http://offerforothers.com");
}
?>
 
Back
Top