PHP to obtain the specified (guest) IP all information (address, postal code, country, latitude and longitude, etc.) method _php Tips

Source: Internet
Author: User

This article describes the method of obtaining all the information (address, ZIP code, country, latitude, etc.) for the specified (guest) IP in PHP. Share to everyone for your reference. Specifically as follows:

Calling the method is very simple. This also requires a database to support. The Chinese and phonetic characters in the database can coexist.

Nonsense not much to say, look at the code:

<?php  
function Getipinfo ($ip, $timeout =15) {  
  if (!function_exists (' curl_init ') or!function_exists (' Simplexml_load_string ') return false;  
  $ch = Curl_init ("http://ipinfodb.com/ip_query2.php?ip={$ip}&timezone=true");  
  $options = Array (  
      Curlopt_returntransfer => true  
    );  
  Curl_setopt_array ($ch, $options);  
  $res = curl_exec ($ch);  
  Curl_close ($ch);  
  
  if ($xml = simplexml_load_string ($res)) {  
    $return = array ();  
    foreach ($xml->location->children () as $key => $item) {  
      $return [$key] = Strtolower ($item);  
    }  
    return $return;  
  } else {return  
    false;  
  }  
}  
$current _ip_info = getipinfo (' 119.7.8.255 ');  
Var_dump ($current _ip_info); 

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.