Get user's current location

Jacek Francuz picture Jacek Francuz · Mar 22, 2011 · Viewed 169.9k times · Source

How can I determine user's current location based on IP (I guess it works this way).

Answer

Hamza picture Hamza · Jul 1, 2015
<?php
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$country = $geo["geoplugin_countryName"];
$city = $geo["geoplugin_city"];
?>