Welcome to WebmasterWorld Guest from 54.167.22.37

Forum Moderators: open

Message Too Old, No Replies

Script for displaying G when visitor is international

how?

     

Clark

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

WebmasterWorld Senior Member 10+ Year Member



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.

dzcap

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

10+ Year Member



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)


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

}
?>

Clark

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

WebmasterWorld Senior Member 10+ Year Member



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.

dzcap

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

10+ Year Member



Can you send me a copy of that script?

Clark

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

WebmasterWorld Senior Member 10+ Year Member



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.

perldiver

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

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

Clark

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

WebmasterWorld Senior Member 10+ Year Member



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?

perldiver

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

asp4bunnies

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

10+ Year Member



I use countryhawk. Pretty innacurate though.

Clark

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

WebmasterWorld Senior Member 10+ Year Member



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.

FTFlash

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

10+ Year Member



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

ksoper78

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

10+ Year Member



Does anyone have thsi code in ASP?

Thanks!

garyr_h

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

WebmasterWorld Senior Member 10+ Year Member



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

FTFlash

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

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month