You can query a GeoIP database in your application code.
See:
http://php.net/manual/en/book.curl.php
http://dev.maxmind.com/geoip/legacy/install/city
See:
http://php.net/manual/en/book.curl.php
http://dev.maxmind.com/geoip/legacy/install/city