Using an API from http://www.ipgp.net/ this snippet demonstrates getting a city from an IP address pass the IP address in a var called $ip and the API key in a var called $apikey.

If the session has not been created then a lookup is done and the city is added to a session.

Copy to Clipboard