Home   |   TWP Auctions   |   Contact
The Website Professionals
Real world webmaster resources.
TWP Auctions - the free eBay script RSS feed Forum

Geo targeting tutorial

Geo targeting

Here’s an incredibly easy way to get geo targeting working on your website. It’s free, and it works pretty well.
You are from US
1. 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…
<?
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;
?>
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…
Bookmark and Share

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.










Featured webmaster products for July 2010:
Use a different photo for every card

Copyright © 2010 The Website Professionals - All rights reserved
Links | Firefox resources | Privacy policy