Forum Moderators: open
If you have this data in mysql, for instance, it's pretty straightforward to check the IP and then use if else code to show different ads.
<?php
// display different content to non-US visitors// this function converts normal IP address to long format, which IP country databases tend to use
function Dot2LongIP ($IPaddr)
{
if ($IPaddr == "") {
return 0;
} else {
$ips = split ("\.", "$IPaddr");
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
}
}// convert the visitors IP - there are better ways of getting the IP than checking REMOTE_HOST, but this is simplest
$lookup_ip=Dot2LongIP($_SERVER[REMOTE_HOST]);// connect to your mysql database and get country info, you would need to configure this to reflect your setup
$db = mysql_connect("localhost", "database_user", "database_pass");
mysql_select_db("ip_to_country_database",$db);
$query = "SELECT country FROM ip_to_country_table WHERE $lookup_ip BETWEEN begin_ip AND end_ip"; $result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$country=$row['country'];// now we know the visitor's location, so display code based on that
if ($country!="US") {// visitor was not from the US - display alternate ads
}
else {// visitor was from the US - display YPN ads
}
?>
-------------------------------------------
sub isinus{
my $isinus=1;
my $user=$ENV{REMOTE_ADDR};
$isinus=0 if $user=~/^62\./;
$isinus=0 if $user=~/^80\./;
$isinus=0 if $user=~/^81\./;
$isinus=0 if $user=~/^82\./;
$isinus=0 if $user=~/^83\./;
$isinus=0 if $user=~/^84\./;
$isinus=0 if $user=~/^85\./;
$isinus=0 if $user=~/^86\./;
$isinus=0 if $user=~/^87\./;
$isinus=0 if $user=~/^88\./;
$isinus=0 if $user=~/^193\./;
$isinus=0 if $user=~/^194\./;
$isinus=0 if $user=~/^195\./;
$isinus=0 if $user=~/^196\./;
$isinus=0 if $user=~/^200\./;
$isinus=0 if $user=~/^201\./;
$isinus=0 if $user=~/^202\./;
$isinus=0 if $user=~/^203\./;
$isinus=0 if $user=~/^212\./;
$isinus=0 if $user=~/^213\./;
$isinus=0 if $user=~/^217\./;
$isinus=0 if $user=~/^218\./;
$isinus=0 if $user=~/^219\./;
$isinus=0 if $user=~/^220\./;
$isinus=0 if $user=~/^221\./;
$isinus=0 if $user=~/^222\./;
return($isinus);
}
-------------------------------------------
Then you do something like:
routineThatShowsYPNad() if isinus();
routineThatShowsAlternateAd() if!isinus();
(note for some strange reason this system will not allow me to type "if space not-symbol something"...)
How's it working? Dunno. I'm doing it just to be on the safe side, but I haven't put YPN on any of my big traffic sites yet so I'm still making zilch...
Still, depends on what level of accuracy you need - you should be able to detect browsers with the language set to english with some level of success.
Their geotragetting feature is MaxMind. It's just integrated into the system... phpadsnew is good, it's just very hefty. Much less resources are taken if you just download the software and make your own code.