Debt Consolidation Loans - Classical Christian Education - Loans - Loans - Adverse Credit Remortgage

PDA

View Full Version : ip sensitve ads


mydomainoffer
Aug 19th 2007, 1:25 pm
has anybody have a script to display yahoo ad for US traffic and adsense for other region...

thanks

Dentman
Aug 19th 2007, 6:30 pm
yeah very good idea to use... may it be against TOS?

PoemofQuotes
Aug 19th 2007, 6:45 pm
It is not against the TOS, they actually want you to use one. Download MaxMind GeoIP lite for free. Then write a simple script like:

<?
$ip = $_SERVER['REMOTE_ADDR'];
include("geoip.inc");

$gi = geoip_open(dirname(__FILE__)."/GeoIP.dat",GEOIP_STANDARD);

if (geoip_country_code_by_addr($gi, $ip) != US) {
$rand = rand(4,5);
}

else {
$rand = rand(3,4);
$place = "US";
}

geoip_close($gi);

?>
Just include that file in your header.php

decodethis
Aug 20th 2007, 7:26 am
That's almost the exact script I use (I use GeoIP as well). It's free and pretty easy to set up. I actually use php includes to insert my ads, making it fairly easy to change whenever I want. I added a USE_YAHOO constant in my headed that I can toggle whenever the YPN "shuts down" so I can go with Adsense ads for all traffic with just changing one setting.

I've been using it for over a year pretty flawlessly.

decodethis
Aug 20th 2007, 7:54 am
Here's mine:

<?php

//Check if an IP address has been submitted, or get the surfer's IP address

if(isset($_GET["ipAddress"]))
$addr=$_GET["ipAddress"];
else {
// Get the surfer's ip address
$addr = getenv("REMOTE_ADDR");
}
//Do the MaxMind geotargeting database lookup
//
require_once("geo/geoip.inc");
$gi = geoip_open("geo/GeoIP.dat",GEOIP_STANDARD);
$country = geoip_country_name_by_addr($gi, $addr);
$countryCode = geoip_country_code_by_addr($gi, $addr);
geoip_close($gi);
// Display the Ad based on Country Code
if (USE_YAHOO) {
if ($countryCode == "US" || $countryCode == "") {
// display Yahoo Ad
include("geo/yahoo_content_block.inc"); }
else {
// display Google Ad
include("geo/google_content_block.inc");
}
}
else
{
include("geo/google_content_block.inc");
}
?>


USE_YAHOO is a global flag I can toggle to turn off YPN ads 100% site-wide.

PoemofQuotes
Aug 20th 2007, 6:41 pm
Nice idea decodethis.

mydomainoffer
Aug 20th 2007, 6:49 pm
i love this community; thanks for sharing the script i will try it out.

thanks again.