Geo Targeting Script

hello can u add redirect script so if visitor from US will redirect to ........


PHP:
<?php 
include("geoip.inc");

$ip = $_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);

$returarray = array(geoip_country_code_by_addr($gi, $ip),geoip_country_name_by_addr($gi, $ip));

//return geoip_country_code_by_addr($gi, $ip);

geoip_close($gi);
echo $returarray[0];

if($returarray[0] == "US"){
header( 'Location:  Url_For_US_Visitors');

}
else if($returarray[0] =="GB"){
header( 'Location:  URL_For_UK_Visitors');
}
else
{
header( 'Location: URL_For_Other_Visitors ');
}

?>
Just put all this code in the index.php and it will work as you want.
Make sure to edit
Code:
  header( 'Location:  *********');
in all the three lines, there must be a complete desired URL with http and www prefix.
IF you think its working fine for you then I will appreciate positive rep and thanks.:D
 
Last edited:
hello, which code to add if i wanna add more country to redirect? thx
 
hello, which code to add if i wanna add more country to redirect? thx
You would need to add


PHP:
else if($returarray[0] =="DESIRED COUTNRY CODE"){
header( 'Location:  DESIRED URL');
}

but you have to add it just above the follwing:


PHP:
else
{
header( 'Location: URL_For_Other_Visitors ');
}
 
hello there's error here, how to fix it?

Parse error
: syntax error, unexpected '}' in /home/xxxx/public_html/mydomain.info/index.php on line 20
 
Please copy this code:

PHP:
<?php 
include("geoip.inc");
$ip = $_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$returarray = array(geoip_country_code_by_addr($gi, $ip),geoip_country_name_by_addr($gi, $ip));
geoip_close($gi);
if($returarray[0] == "US"){
header( 'Location:  Url_For_US_Visitors');
}
else if($returarray[0] =="GB"){
header( 'Location:  URL_For_UK_Visitors');
}
else{
header( 'Location: URL_For_Other_Visitors ');
}
?>
 
Last edited:
I get this error when I go to index.php

Fatal error: Cannot redeclare geoip_country_code_by_name() in /home/domain/public_html/GeoTargetting/geoip.inc on line 390
 
I get this error when I go to index.php

Fatal error: Cannot redeclare geoip_country_code_by_name() in /home/domain/public_html/GeoTargetting/geoip.inc on line 390
please download this file
173.242.114.124/GeoTargetting/geoip.rar
and replace here
/home/domain/public_html/GeoTargetting/
you can see its working fine at my server at following URL
173.242.114.124/GeoTargetting
 
hey, can i use this to redirect someone to a specif page based on their city location?
 
hey, can i use this to redirect someone to a specif page based on their city location?
yes you can, you will just need to modify little php code and it will do as you wanted. Please read relevant information in post #24 of this thread.
 
Is this the original geoip script from maxmind? If so that's soo cool. How can I redirect traffic based on their postal code?
 
@trozma & @thisismymp3
Yes original script that MaxMind uses. And its possible redirect traffic based on Postal Codes or City Names but not recommended. But its always good to redirect based on country.
 
i used maxmind geotarget script previously, but not as big as 16mb.. i think country is the most important factor rather than the specifying the cities or go by postal code as most cpa will accept the whole country traffic in general..
 
@jeremyok

You are right, the size of the database is getting bigger day by day as the addition of new IPS on www could not be stopped.
 
So they're constantly adding new IPs to the database?
Can somebody explain what's the procedure used to add new IPs? I mean, does every country always have the same digits in the IP - like yyy.xxx.xxx.xxx, where yyy is always assigned to the same country?
 
Does maxmind geoip database included in this download have to be updated every month? If not, I must be confusing it with another maxmind database?
 
Can this work together with cpa-r2? And how?
Cause for Twitter traffic I need a safe referer replacement, but geotargeting would come in very handy as well...
 
Back
Top