There are many cases that we need to display different content to our users depending on the location that they are visiting our site. In this tutorial we will give some examples regarding geo targeting with php.
First of all I would like to say how geotargeting is important for the monetization of a web site. For instance you can use adsense and replace one good spot with an affiliate advertisement only for US visitors (as US are buying more frequently). Additionally there are many ad networks (eg. Yahoo publisher network) that require to display their ads only to US visitors, or others that pay more for US visitors.
There are many ways to implement this in your web site, though the most simple I found is by using Maxmind's geolocation database(there is a free version in their site)
After you download the database, you need to get the pure php module which is an API for the database (the database is a text file)
Put those two in a directory, and now you are done. Here is how you can use it to identify if someone is coming from United States :