Taobao IP Address Library Web site: http://ip.taobao.com/
The provided services include:
1. Based on the IP address provided by the user, quickly query the geographic information and geographical information of the IP address, including the country, province, city, and carrier.
2. You can update our service content based on your location and IP address.
Interface description:
1. Request interface (GET method ):
Http://ip.taobao.com/service/getIpInfo.php? Ip = [ip address string]
2. Response Information (json format data ):
Country, province (autonomous region or municipality), City (county), operator
3. Returned data format:
The code is as follows: |
Copy code |
{"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 "}} |
The meaning of the code value is: 0: successful, 1: failed.
4. PHP sample code:
The code is as follows: |
Copy code |
Function getCity ($ ip) { $ Url = "http://ip.taobao.com/service/getIpInfo.php? Ip = ". $ ip; $ Ip = json_decode (file_get_contents ($ url )); If (string) $ ip-> code = '1 '){ Return false; } $ Data = (array) $ ip-> data; Return $ data; } $ Ip = '1970. 216.64.183 '; Print_r (getCity ($ ip); exit; |
5. Get the php code of the IP address
<? Php
Error_reporting (E_ERROR | E_WARNING | E_PARSE );
If ($ HTTP_SERVER_VARS ["HTTP_X_FORWARDED_FOR"]) {
$ Ip = $ HTTP_SERVER_VARS ["HTTP_X_FORWARDED_FOR"];
}
Elseif ($ HTTP_SERVER_VARS ["HTTP_CLIENT_IP"]) {
$ Ip = $ HTTP_SERVER_VARS ["HTTP_CLIENT_IP"];
}
Elseif ($ HTTP_SERVER_VARS ["REMOTE_ADDR"]) {
$ Ip = $ HTTP_SERVER_VARS ["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 ";
}
Echo $ ip;
?>