Script to determine if my visitors are in US

Status
Not open for further replies.

divine

New member
Feb 3, 2007
204
1
0
Hi

I joined copeac and other CPA networks. Many of the good CPLs programs are available only for US residents.

My websites receives traffic from all countries. Is there any easy solution, so that I am able to show the banner only to my US visitors (and not to other countries)?

Cheers!
 


Get the Maxmind database (the free one) and grab the geoip.inc file then write something like the following. In the $ads variable just put the javascript or HTML provided by Copeac or whoever. You can then reference it in your template or just echo it later as required. Works well enough. The default case is for the ad that gets displayed when the user is not from, in this case, the UK, US or Australia.

Code:
include('geoip.inc'); // include the geoip functions
$geofile = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$cn= geoip_country_name_by_addr($geofile, $_SERVER['REMOTE_ADDR']);

switch ($cn) {
case "United Kingdom": {
$ads="";
break;
}
case "United States": {
$ads="";
break;
}
case "Australia": {
$ads="";
break;
}
case default: {
$ads="";
break;
}
}

geoip_close($geofile);
 
Get the Maxmind database (the free one) and grab the geoip.inc file then write something like the following. In the $ads variable just put the javascript or HTML provided by Copeac or whoever. You can then reference it in your template or just echo it later as required. Works well enough. The default case is for the ad that gets displayed when the user is not from, in this case, the UK, US or Australia.

Code:
include('geoip.inc'); // include the geoip functions
$geofile = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$cn= geoip_country_name_by_addr($geofile, $_SERVER['REMOTE_ADDR']);

switch ($cn) {
case "United Kingdom": {
$ads="";
break;
}
case "United States": {
$ads="";
break;
}
case "Australia": {
$ads="";
break;
}
default: {
$ads="";
break;
}
}

geoip_close($geofile);

Works like a charm. In case anyone else uses the above code, don't write "case" with "default".

Cheers!!!
 
Status
Not open for further replies.