Get country, city, region, lat, lang, country code, and location details based IP address. here we have PHP code to find the above all location details based on IP address. Based on IP address we can get more details about city, country, country code, latitude, longitude, region code, region name and some more details only based on IP address. Let see the code.
PHP CODE DISPLAY ALL DETAILS BASED ON IP ADDRESS [DEMO]
<?php function getiplocationdetails(){ $remoteip = @$_SERVER['REMOTE_ADDR']; $ip = $remoteip; $result = ''; $ip_datails = @json_decode (file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip)); return $ip_datails; } echo "<pre>"; print_r(getiplocationdetails()); ?>
PHP CODE DISPLAY FEW DETAILS BASED ON IP ADDRESS [DEMO]
<?php function getiplocationdetails(){ $clientip = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remoteip = @$_SERVER['REMOTE_ADDR']; $result = array('country'=>'', 'city'=>'','region'=>''); if(filter_var($clientip, FILTER_VALIDATE_IP)){ $ip = $clientip; }elseif(filter_var($forward, FILTER_VALIDATE_IP)){ $ip = $forward; }else{ $ip = $remoteip; } $ip_datails = @json_decode (file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip)); if($ip_datails && $ip_datails->geoplugin_countryName != null){ $result['country'] = $ip_datails->geoplugin_countryCode; $result['city'] = $ip_datails->geoplugin_city; $result['region'] = $ip_datails->geoplugin_region; } return $result; } echo '<pre>'; print_r(getiplocationdetails()); ?>
I hope this code really helpful to you. keep visiting for more tutorials like this.
Wrong, I have tested demo and I am from ahmedabad and it's showing Mumbai....
ReplyDelete@Vinay Suthar. It will fetch the data only based on you Ip Address.
DeleteOhh Got It...
DeleteThanks Arun, for sharing this code...
Thanks for sharing this code, it works well
ReplyDeleteAm at Lagos and it capture it.
ReplyDeleteThe above code getting delay in mobile. Any alternative solution?
ReplyDeleteIts working showing blank data.
ReplyDeleteSuperior post, keep up with this exceptional work. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! IP Address
ReplyDeletehow can i get street address. ?
ReplyDelete