my simple script use freegeoip.net API, not need database.
PHP:
<?php
/*
script name: GeoTargeted ads
author: Ogah
site URL: http://indro-network.blogspot.com/2013/08/php-geo-targeted-content-atau-geo.html
*/
$urlgeo = "http://www.freegeoip.net/json/".$_SERVER['REMOTE_ADDR'];
$geo = file_get_contents($urlgeo);
$jsgeo = json_decode($geo, true);
$negara = $jsgeo['country_code'];
if($negara == 'US') {
// put your ads or content that targeted to US visitor here
}
else {
// put content or ads for other country visitor here
}
?>