Geo targeting tutorial

You are from US1. Download GeoIP.dat.gz from MaxMind.com, extract it (using WinRAR or 7-Zip), then upload GeoIP.dat to your server.
2. Download geoip.inc and upload it to your server.
3. You should now have GeoIP.dat and geoip.inc on your server.
4. Try the example PHP code below, it simply prints our the two letter country code – but once you’ve got the visitor’s location, you can then redirect them or serve up geo targeted ads etc…
<?If you read through geoip.inc you’ll find that there are more things you can do, such as getting the visitor’s location by name (e.g Germany) etc…
function get_country_code ($ip) {
include_once("geoip.inc");
$gi = geoip_open(dirname(__FILE__)."/GeoIP.dat",GEOIP_STANDARD);
$country_code = (geoip_country_code_by_addr($gi, $ip)) ;
geoip_close($gi);
return $country_code;
}
$userlocation = (get_country_code($_SERVER["REMOTE_ADDR"]));
// you can now use $userlocation to send ‘au’ people to an Australian page, or ‘in’ people to an Indian page etc… but we’ll just print it out for now.
echo $userlocation;
?>





Comments
Chris
February 19, 2011How do i echo the user location?
Like country code (e.g: Australia)
Thanks
Plans for Chicken Coops
April 10, 2011Hey,
Nice post. I’m curious though. Will this help you rank in the serps for a specific city?
Leave a comment
This is a dofollow website. If you leave a comment, then we'll give you a backlink.Please be aware that this website is strictly moderated. If you post spam, you'll get a slap.