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); ?> Code (markup): Just include that file in your header.php
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.
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"); } ?> PHP: USE_YAHOO is a global flag I can toggle to turn off YPN ads 100% site-wide.