Hi DP members and php master, Is there any free or paid web services that can be used for geo location checking. i want to pass the IP of the current visitor/user to a webservice/site then this will return give me the visitors country.
http://pecl.php.net/geoip You will need maxmind GeoIP installed. There is a free database/service. On a lot of systems, this will get you going: Where {pkgmanager} is yum, or apt-get {pkgmanager} install GeoIP Code (markup): pecl install geoip Code (markup): echo "extension=geoip.so" > /etc/php.d/geoip.ini Code (markup): If you use php-fpm then service php-fpm restart Code (markup): If you use nginx or apache, then execute Where {httpd} is httpd, or nginx service {httpd} restart Code (markup): You will need to add a cron job for monthly updates to the GeoIP.dat
Thanks Krakjoe for the prompt response. But i'm using a shared hosting, will they allow me to install it?
There are other implementations that you can use on a shared server: http://www.phpclasses.org/search.html?words=geoip&x=0&y=0&go_search=1 If you just want the country name/code, the first class listed by Marius seems sufficient.
You can still use an API which is relatively fast if you can't afford to install the standalone db from maxmind. (http://freegeoip.net/{FORMAT}/{IP_OR_HOSTNAME}) Example : http://freegeoip.net/json/79.112.239.66 (csv, xml is available too) JSON callbacks are supported by adding the callbackargument to the query string: http://freegeoip.net/json/79.112.239.66?callback=show which results into: show({"city": "Vaslui", "region_code": "38", "region_name": "Vaslui", "metrocode": "", "zipcode": "", "longitude": "27.7333", "latitude": "46.6333", "country_code": "RO", "ip": "79.112.239.66", "country_name": "Romania"}); Code (markup):