If you market products to a large geographical target, then you may be wondering how to show items based on the location of your users. The main problem is, this information is not shared by just looking at the visitor. At most, site owners get an IP address for the average user, unless this information is shared voluntarily, such as with a member account.
We decided to write a simple script and database solution for using Maxmind's GeoIP2 Precision Service with the City subscription. Queries are very cheap and flexible, so this is pretty simple to use if you have experience with PHP. This is set up for products, however if you're a little savvy, then you can also use it for categories, links or whatever you can dream about.
We recommend deleting IP addresses every several months, depending on the dependency needs you have - to refresh the data, since IP addresses get re-assigned often.
Naturally, a database is required for storing both the IP, city, country data - as well as a comma separated list of the states that you want to target for the product. It has been tested on PHP version 5.2x with mySql v5.6x on an Apache server. There is no reason to believe it will not work on all versions, with PHP >= 5.
- Download the sample Geo PHP files to integrate Geo services into your site, and happy geoing!