Helo there! In these last days one client of mine asked me how to prevent non-italian visitors from seeing national ADS when they visit one or more websites.
The solution comes alog with builtin geoip functions in the php5-geoip package to be installed as usual using apt-get
After installed this package typing:
apt-get install php5-geoip
Now, what you have is a countries database, and if you want to be much more precise (as me for example) you can download a detailed Cities database typing the following set of commands:
sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
Now you own the entire planet cities database! 🙂
Let’s try it within a PHP web page: create a new file (or edit an existent one) and type:
It should return something like this:
Array ( [country_code] => US [country_code3] => USA [country_name] => United States [region] => CA [city] => Sunnyvale [postal_code] => 94089 [latitude] => 37.4249000549 [longitude] => -122.007400513 [dma_code] => 807 [area_code] => 408 )
Comments or questions are welcome, Also if you neew to setup a geo based service, now you know who could do it for you!