In this article, we will explain to you how to get visitors country from their IP in PHP. here we will give you a simple example from getting your visitor’s geolocation.
Sometimes we need to a particular country and we only want to display or hide it for visitors from that country. or sometimes we may want to auto-redirect translation page using a specific country wise.
In this example, we can easily get country, state, and city using the geoip location. so we are using the geolocation API, so you can check our code in different countries.
<?php $ip_address=$_SERVER['REMOTE_ADDR']; $geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address; $addrDetails = unserialize(file_get_contents($geopluginURL)); echo "<pre>"; print_r($addrDetails); echo "</pre>"; ?>
Please follow and like us: