You have generally seen that when you access some site, it show your location. This location on site is retrieved by IP address of visitors. I have also required this concept in my own project and decide to write the snippet. In this tutorial you will see how to retrieve country name and City name of visitor through IP Address. Here I have written small snippet to get visitor address information.
You can see demo which is shown below:
Let us see the given below snippet to understand how to get address detail by IP. Given below is PHP code by which we are retrieving Country and City name from IP using Gelocation.net site.
/*Getting user IP address details with geoplugin.net*/
$addr_details = @unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip_address));
$city = $addr_details['geoplugin_city'];
$countrycode = $addr_details['geoplugin_countryCode'];
$country = $addr_details['geoplugin_countryName'];
echo "<b>"."City Name:"."</b>".$city."<br>";
echo "<b>"."Country Code:"."</b>".$countrycode."<br>";
echo "<b>"."Country Name:"."</b>".$country."<br>";