homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Yahoo / Yahoo Publisher Contextual Advertising Network
Forum Library, Charter, Moderator: open

Yahoo Publisher Contextual Advertising Network Forum

  posting off  
Script for displaying G when visitor is international

 7:11 am on Nov 14, 2005 (gmt 0)

Any coders familiar w/ geocoding know how to detect where the visitor is coming from and offer them G when they aren't in the US. I bet that would upgrade CTR for Y! immediately.


Receptional Andy

 4:43 pm on Nov 14, 2005 (gmt 0)

Detecting location is not too difficult once you have an accurate database of IPs to locations. There's lot of them about - www.maxmind.com offer a free one which they claim is 97% accurate and I've used in the past. There are some paid ones with other useful info in them.

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.


 4:45 pm on Nov 14, 2005 (gmt 0)

Does anyone have a tutorial on how to do this?

Receptional Andy

 4:55 pm on Nov 14, 2005 (gmt 0)

If we assume that you have a mysql IP to country database that contains the location of IP ranges in long format and corresponding country codes (this seems to be fairly typical) you could use something like the below (unchecked)

// 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

// 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");
$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);

// 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



 6:54 pm on Nov 14, 2005 (gmt 0)

I wrote something similar last night after seeing a post giving some ranges of non-US IPs. It is much simpler. No database. Probably not that accurate but if I get 80-90% and don't need to add a database call it's worth it.


 7:19 pm on Nov 14, 2005 (gmt 0)

Can you send me a copy of that script?


 7:24 pm on Nov 14, 2005 (gmt 0)

It's all embeded in my system but I'll dig it up within the next day or so and post what I got. No idea if it's effective or not.


 7:53 pm on Nov 14, 2005 (gmt 0)

Here's how I do it on my sites in perl. The IPs are from a list posted here recently.


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\./;



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"...)


 8:05 pm on Nov 14, 2005 (gmt 0)

Thanks perldiver. My code is almost identical except I pull out the first subnet and do ranges instead of one line per subnet.

How's that working for you?


 9:10 pm on Nov 14, 2005 (gmt 0)

Yes, sometimes I sacrifice "pretty" for "maintainability"...

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...


 9:18 pm on Nov 14, 2005 (gmt 0)

I use countryhawk. Pretty innacurate though.


 7:39 am on Nov 28, 2005 (gmt 0)

Is this code achievable in javascript?

Receptional Andy

 9:32 am on Nov 28, 2005 (gmt 0)

I'd have to say no, because there's no way to check a visitors IP with javascript alone. The only possible method I can think of would be using something like the browsers language setting, but this would be very unreliable since many browsers run as the default.

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.


 6:42 am on Nov 29, 2005 (gmt 0)

Doesn't PHPAdsNew have a geotargetting feature? Is anyone experimented with it? Is it good?


 2:11 pm on Dec 3, 2005 (gmt 0)

Does anyone have thsi code in ASP?



 4:43 pm on Dec 3, 2005 (gmt 0)

"Doesn't PHPAdsNew have a geotargetting feature? Is anyone experimented with it? Is it good?"

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.


 7:05 pm on Dec 3, 2005 (gmt 0)

I think I'll download MaxMind. Thanks for the help.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Yahoo / Yahoo Publisher Contextual Advertising Network
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved