You can access this service using server IP address.Use PHP reserved variable to get IP.
$what_is_my_ip = $_SERVER['REMOTE_ADDR'];
As an example, the following PHP snippet
echo var_export( unserialize( file_get_contents( 'http://www.geoplugin.net/php.gp?ip = '.$_SERVER['REMOTE_ADDR'] ) ) );
output:
array (
'geoplugin_request' => '182.75.235.222',
'geoplugin_status' => 206,
'geoplugin_credit' => 'Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.',
'geoplugin_city' => '',
'geoplugin_region' => '',
'geoplugin_areaCode' => '0',
'geoplugin_dmaCode' => '0',
'geoplugin_countryCode' => 'IN',
'geoplugin_countryName' => 'India',
'geoplugin_continentCode' => 'AS',
'geoplugin_latitude' => '20',
'geoplugin_longitude' => '77',
'geoplugin_regionCode' => '',
'geoplugin_regionName' => '',
'geoplugin_currencyCode' => 'INR',
'geoplugin_currencySymbol' => '₨',
'geoplugin_currencySymbol_UTF8' => '₨',
'geoplugin_currencyConverter' => '67.8358',
)
Also you can use php function to get specific value from array response.
function getLocationInfoByIp($ip_addr)
{
$return_data = array('country'=>'', 'city'=>'');
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip_addr));
if($ip_data && $ip_data->geoplugin_countryName != null)
{
$ret = $ip_data->geoplugin_countryName;
if($ip_data->geoplugin_city != null){
$ret .= ', '.$ip_data->geoplugin_city;
}
return $ret;
}
}
$loc=getLocationInfoByIp($_SERVER['REMOTE_ADDR']);
0 Comments