Home php教程 php手册 淘宝IP地址库API接口(PHP)通过ip获取地址信息

淘宝IP地址库API接口(PHP)通过ip获取地址信息

May 25, 2016 pm 04:44 PM
api interface

淘宝IP地址库网址:http://ip.taobao.com/

提供的服务包括:

1. 根据用户提供的IP地址,快速查询出该IP地址所在的地理信息和地理相关的信息,包括国家、省、市和运营商.

2.用户可以根据自己所在的位置和使用的IP地址更新我们的服务内容.

接口说明:

1. 请求接口(GET方式):

http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串]
Copy after login

2.响应信息(json格式数据):

国家 、省(自治区或直辖市)、市(县)、运营商

3. 返回数据格式,代码如下:

{"code":0,"data":{"ip":"210.75.225.254","country":"u4e2du56fd","area":"u534eu5317", 
"region":"u5317u4eacu5e02","city":"u5317u4eacu5e02","county":"","isp":"u7535u4fe1", 
"country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000", 
"county_id":"-1","isp_id":"100017"}}
Copy after login

其中code的值的含义为,0:成功,1:失败.

4. PHP代码示例:

<?php
function getCity($ip) {
    $url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
    $ip = json_decode(file_get_contents($url));
    if ((string)$ip->code == &#39;1&#39;) {
        return false;
    }
    $data = (array)$ip->data;
    return $data;
}
$ip = &#39;221.216.64.183&#39;;
print_r(getCity($ip));
exit;
?>
Copy after login

5.获取IP地址php代码

<?php
if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
    $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif ($_SERVER["HTTP_CLIENT_IP"]) {
    $ip = $_SERVER["HTTP_CLIENT_IP"];
} elseif ($_SERVER["REMOTE_ADDR"]) {
    $ip = $_SERVER["REMOTE_ADDR"];
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
    $ip = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("HTTP_CLIENT_IP")) {
    $ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("REMOTE_ADDR")) {
    $ip = getenv("REMOTE_ADDR");
} else {
    $ip = "Unknown";
}
?>
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Email Sending API Interface Guide in PHP Email Sending API Interface Guide in PHP May 21, 2023 pm 12:12 PM

With the popularity of email in our daily lives, email sending has become an essential feature in many applications. As a popular web development language, PHP also provides a corresponding email sending API interface. This article will introduce the email sending API interface in PHP to beginners and developers, including how to configure the mail server, how to use PHP's built-in email functions, and how to use a third-party email sending library. 1. Configure the mail server. Before using PHP to send mail, you need to first configure an SMTP server.

What are the free API interface websites? What are the free API interface websites? Jan 05, 2024 am 11:33 AM

Free api interface website: 1. UomgAPI: a platform that provides stable and fast free API services, with over 100 API interfaces; 2. free-api: provides multiple free API interfaces; 3. JSON API: provides free data API interface; 4. AutoNavi Open Platform: Provides map-related API interfaces; 5. Face recognition Face++: Provides face recognition-related API interfaces; 6. Speed ​​data: Provides over a hundred free API interfaces, suitable for various needs In the case of data sources; 7. Aggregate data, etc.

What are the main types of api interfaces? What are the main types of api interfaces? Apr 23, 2024 pm 01:57 PM

API interface types are rich and diverse, including RESTful API, SOAP API, GraphQL API, etc. RESTful API communicates through the HTTP protocol, with a simple and efficient design, which is the current mainstream Web API design style. SOAP API is based on XML, focuses on cross-language and platform interoperability, and is mostly used in large enterprises and government agencies. GraphQL API is a new query language and runtime environment that supports flexible data query and response.

What is the API interface for? What is the API interface for? Apr 23, 2024 pm 01:51 PM

An API interface is a specification for interaction between software components and is used to implement communication and data exchange between different applications or systems. The API interface acts as a "translator", converting the developer's instructions into computer language so that the applications can work together. Its advantages include convenient data sharing, simplified development, improved performance, enhanced security, improved productivity and interoperability.

Precautions and techniques in PHP Tencent Cloud Server API interface docking Precautions and techniques in PHP Tencent Cloud Server API interface docking Jul 06, 2023 am 10:13 AM

PHP Tencent Cloud Server API Interface Precautions and Tips Tencent Cloud, as the leading domestic cloud computing platform provider, its cloud server (CVM) products are favored by many developers and enterprises. In order to better connect with Tencent Cloud servers, Tencent Cloud provides a rich API interface to facilitate developers to perform various operations and management. This article will introduce matters needing attention and some techniques when connecting to the Tencent Cloud server API interface in a PHP environment. At the same time, we will give some code examples for better

How to build an API interface using Go language and Redis How to build an API interface using Go language and Redis Oct 27, 2023 pm 01:23 PM

Overview of how to use Go language and Redis to build API interfaces: Go language (Golang) is a concise, efficient, and powerful programming language, while Redis is an open source in-memory database that provides rich data structures and powerful query functions. This article will introduce how to use Go language and Redis to build API interfaces, and provide specific code examples. Step 1: Install and configure the Go language environment. First, you need to install the Go language on your computer and set the relevant environment variables. After completing this step

Developing API documentation: A step-by-step guide to PHP API interfaces Developing API documentation: A step-by-step guide to PHP API interfaces Jan 22, 2024 am 11:20 AM

With the increasing popularity of web applications, APIs (Application Programming Interfaces) are becoming more and more important and playing an increasingly important role in web development. WebAPI is a technology that allows users to access applications through the Internet. It is a basic tool for combining different applications. PHP is a widely used programming language, especially in the field of web development. Developers can allow other applications to use their application functionality by developing PHP API interfaces. In order to achieve this

What does api interface mean? What does api interface mean? Mar 13, 2023 pm 03:15 PM

The api interface means application programming interface. It is a set of predefined functions that provide applications and developers with the ability to access a set of routines based on certain software or hardware. Good interface design can reduce the cost of each part of the system. Interdependence improves the cohesion of component units and reduces the degree of coupling between component units, thereby improving the maintainability and scalability of the system.

See all articles