Getting user location from an IP address

Want to retrieve information like the city, state, and country of a visitor from their IP address?

PHP example:

ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
echo $details->city;

 

jQuery example:

$.get("http://ipinfo.io", function(response) {
    console.log(response.city);
}, "jsonp");

 

Source: http://stackoverflow.com/questions/409999/getting-the-location-from-an-ip-address#answer-17864552

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>