Help PHP Script

Support on setups where you copy the hostip.info database locally.

Moderator: Moderators

Help PHP Script

Postby TestIP on Tue Jan 22, 2008 3:54 am

Hi,

Can anyone help me with a simple php script to use the local IP database?
* My last message was deleted without reason.

Thanks.
TestIP
n00b
 
Posts: 1
Joined: Tue Jan 15, 2008 5:50 am

Re: Help PHP Script

Postby healingrooms on Mon Feb 09, 2009 2:02 pm

Here is some PHP code that will get the latitude, longitude, city, state and country from hostip.info.

Code: Select all
   $ip=$_SERVER['REMOTE_ADDR'];
   
      function StripTags_IP($string){
         while(strstr($string, '>')){
            $currentBeg = strpos($string, '<');
            $currentEnd = strpos($string, '>');
            $tmpStringBeg = @substr($string, 0, $currentBeg);
            $tmpStringEnd = @substr($string, $currentEnd + 1, strlen($string));
            $string = $tmpStringBeg.$tmpStringEnd;
         }
         return $string;
      }
      
      function GetCountry_IP($IP){
         $lines = @StripTags_IP(file('http://api.hostip.info/get_html.php?ip='.$IP));
         return substr($lines[0], 9);
      }
      
      function GetCity_IP($IP){
         $lines = @StripTags_IP(file('http://api.hostip.info/get_html.php?ip='.$IP));
         $pos = -(strlen($lines[1]) - strpos($lines[1], ','));
         return substr($lines[1], 6, $pos);
      }
      
      function GetState_IP($IP){
         $lines = @StripTags_IP(file('http://api.hostip.info/get_html.php?ip='.$IP));
         $pos = strpos($lines[1], ',')+2;
         return substr($lines[1], $pos, 2);
      }
   
      function GetLatitude_IP($IP){
         $lines = @StripTags_IP(file('http://api.hostip.info/get_html.php?ip='.$IP.'&position=true'));
         return substr($lines[2], 10);
      }
   
      function GetLongitude_IP($IP){
         $lines = @StripTags_IP(file('http://api.hostip.info/get_html.php?ip='.$IP.'&position=true'));
         return substr($lines[3], 11);
      }
   
      
   $latitude=GetLatitude_IP($_SERVER['REMOTE_ADDR']);
   $longitude=GetLongitude_IP($_SERVER['REMOTE_ADDR']);
   $cityname=GetCity_IP($_SERVER['REMOTE_ADDR']);
   $statename=GetState_IP($_SERVER['REMOTE_ADDR']);
   $countryname=GetCountry_IP($_SERVER['REMOTE_ADDR']);
healingrooms
n00b
 
Posts: 3
Joined: Mon Feb 09, 2009 1:07 pm


Return to Hostip.info database local copy support

Who is online

Users browsing this forum: No registered users and 2 guests

cron