Use Taobao IP library to get user IP location _php instance

Source: Internet
Author: User
Tags get ip
Taobao announced their IP library http://ip.taobao.com/, as well as the rest API interface, but each user's access frequency should be less than 10QPS, access mode: http://ip.taobao.com/service/ Getipinfo.php?ip=[ip address string], returns the content in JSON format. With IP query, IP statistics and other functions. The number of IP owned by the major operators and other information. Next, let's take an example of getting IP:
Copy Code code as follows:

<?php
/**
* Get IP location through Taobao IP interface
* @param string $ip
* @return: string
**/
function Getcity ($IP)
{
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=". $ip;
$ipinfo =json_decode (file_get_contents ($url));
if ($ipinfo->code== ' 1 ') {
return false;
}
$city = $ipinfo->data->region. $ipinfo->data->city;
return $city;
}
Header ("Content-type:text/html;charset=utf-8");
Var_dump (getcity ("112.234.69.189"));
?>

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.