Use API to get the details of the visitor’s IP: Here, we are going to use the geoPlugin API to get the details of the visitor. The api will deliver a json object, which can convert to a PHP variable. |
Example:
PHP
<?php
// PHP code to obtain country, city,
// continent, etc using IP Address
$ip = '52.25.109.230';
// Use JSON encoded string and converts
// it into a PHP variable
$ipdat = @json_decode(file_get_contents(
"http://www.geoplugin.net/json.gp?ip=" . $ip));
echo 'Country Name: ' . $ipdat->geoplugin_countryName . "\n";
echo 'City Name: ' . $ipdat->geoplugin_city . "\n";
echo 'Continent Name: ' . $ipdat->geoplugin_continentName . "\n";
echo 'Latitude: ' . $ipdat->geoplugin_latitude . "\n";
echo 'Longitude: ' . $ipdat->geoplugin_longitude . "\n";
echo 'Currency Symbol: ' . $ipdat->geoplugin_currencySymbol . "\n";
echo 'Currency Code: ' . $ipdat->geoplugin_currencyCode . "\n";
echo 'Timezone: ' . $ipdat->geoplugin_timezone;
?>
How to get country details from ip address using PHP | PHP Network Tutorial |
How to extract ip to country? | PHP Network Tutorial |
Read Full: | PHP Network Tutorial |
Category: | Web Tutorial |
Sub Category: | PHP Network Tutorial |
Uploaded: | 8 months ago |
Uploaded by: | Admin |
Views: | 45 |