Showing posts with label state. Show all posts
Showing posts with label state. Show all posts

Friday 18 July 2014

How to get IP based country,state,currency and countrycode and Internet connection Provider and lattitude & longitude in PHP?

<?php
echo getipaddress();
function getipaddress(){
   $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".getRealIpAddr());
   print_r($xml);
   $ccode=$xml->geoplugin_countryCode;
   return $ccode;
}
function getRealIpAddr(){
   if (!empty($_SERVER['HTTP_CLIENT_IP']))  
   {
  $ip=$_SERVER['HTTP_CLIENT_IP'];
 }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))  
 {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
 }else{
  $ip=$_SERVER['REMOTE_ADDR'];
 }
 //$ip="YOUR IP";
 return $ip;
}
   
echo "<hr>";
$details = ip_details(getRealIpAddr());
print_r($details);

function ip_details($ip) {
    $json = file_get_contents("http://ipinfo.io/{$ip}");
    $details = json_decode($json);
    return $details;
}


?>