ip地址库 新浪,淘宝
原文连接地址:http://www.9958.pw/post/city_ip
function getAddressFromIp($ip){
$urlTaobao = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
$urlSina = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$ip;
$json = file_get_contents($urlTaobao);
$jsonDecode = json_decode($json);
if($jsonDecode->code==){//如果取不到就去取新浪的
$data['country'] = $jsonDecode->data->country;
$data['province'] = $jsonDecode->data->region;
$data['city'] = $jsonDecode->data->city;
$data['isp'] = $jsonDecode->data->isp;
return $data;
}else{
$json = file_get_contents($urlSina);
$jsonDecode = json_decode($json);
$data['country'] = $jsonDecode->country;
$data['province'] = $jsonDecode->province;
$data['city'] = $jsonDecode->city;
$data['isp'] = $jsonDecode->isp;
$data['district'] = $jsonDecode->district;
return $data;
}
}
PS:在使用的时候发现,反馈的速度有时候会比较慢,影响了网站速度。
分开操作
/**
* 调用淘宝地址库
* */
function ip_taobao($ip){
$urlTaobao = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
$json = file_get_contents($urlTaobao);
$jsonDecode = json_decode($json);
$data['country'] = $jsonDecode->data->country;
$data['province'] = $jsonDecode->data->region;
$data['city'] = $jsonDecode->data->city;
$data['isp'] = $jsonDecode->data->isp;
return $data;
}
/**
* 调用新浪地址库
* */
function ip_sina($ip){
$data = '';
$urlSina = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$ip;
$json = file_get_contents($urlSina);
$jsonDecode = json_decode($json);
if($jsonDecode == '-2'){
$data['error'] = '未分配或者内网IP';
}else{
$data['country'] = $jsonDecode->country;
$data['province'] = $jsonDecode->province;
$data['city'] = $jsonDecode->city;
$data['isp'] = $jsonDecode->isp;
$data['district'] = $jsonDecode->district;
}
return $data;
}
调用
/**
* 返回ip所在位置
* */
public function ip_address($ip=''){
if (empty($ip)) $ip = request()->ip();
$info = Model('site')->info();
if($info['ip_library'] ==){
$arr= ip_taobao($ip);
}else{
$arr= ip_sina($ip);
}
$address = implode(' ',$arr);
return $address;
}
新的用法
$ip = Request()->ip();
$ip_info = ip_sina($ip);
if($ip_info['country']!='未分配或者内网IP'){
$address = implode(' ',$ip_info);
}else{
$address = '未分配或者内网IP';
}
print_r($address);
最完美的地址库
/**
* 调用淘宝地址库
* */
function ip_taobao($ip){
//$ip = '113.87.131.159';
$opt = [
'http'=>[
'method'=>'GET',
'timeout'=>
]
];
$context = stream_context_create($opt);
$urlTaobao = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
$json = @file_get_contents($urlTaobao,false,$context);
$jsonDecode = json_decode($json);
if($jsonDecode){
$data['country'] = $jsonDecode->data->country;
$data['province'] = $jsonDecode->data->region;
$data['city'] = $jsonDecode->data->city;
$data['isp'] = $jsonDecode->data->isp;
}else{
$data['country'] = '无法连接网络';
}
return $data;
}
/**
* 调用新浪地址库
* */
function ip_sina($ip){
//$ip = '113.87.131.159';
$opt = [
'http'=>[
'method'=>'GET',
'timeout'=>
]
];
$context = stream_context_create($opt);
$data = '';
$urlSina = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$ip;
$json = @file_get_contents($urlSina,false,$context);
$jsonDecode = json_decode($json);
if($jsonDecode){
if($jsonDecode == '-2'){
$data['country'] = '未分配或者内网IP';
}else{
$data['country'] = $jsonDecode->country;
$data['province'] = $jsonDecode->province;
$data['city'] = $jsonDecode->city;
$data['isp'] = $jsonDecode->isp;
$data['district'] = $jsonDecode->district;
}
}else{
$data['country'] = '无法连接网络';
}
return $data;
}
ip地址库 新浪,淘宝的更多相关文章
- WordPress使用淘宝IP地址库的API显示评论者的位置信息(二)
1 淘宝IP地址库的接口说明 在上一篇文章<WordPress使用淘宝IP地址库的API显示评论者的位置信息(一)>中,vfhky使用了新浪工具提供的这个IP接口显示博客评论者的位置信息. ...
- 淘宝ip地址库接口会导致TTFB时间变长,网站打开速度变慢
前一段时间闲来无事发现别人的网站上有显示当前用户城市的功能,就自己也整了一个 这是淘宝ip地址库调用方法 然后问题就出现了,网站打开速度慢的要死 用F12发现是TTFB太慢,然后百度了,发现了问题的原 ...
- 用淘宝ip地址库查ip
这是一个通过调用淘宝ip地址库实现ip地址查询的功能类 using System; using System.Collections.Generic; using System.Linq; using ...
- Delphi使用JSON解析调用淘宝IP地址库REST API 示例
淘宝IP地址库:http://ip.taobao.com,里面有REST API 说明. Delphi XE 调试通过,关键代码如下: var IdHTTP: TIdHTTP; RequestURL: ...
- 淘宝IP地址库采集器c#代码
这篇文章主要介绍了淘宝IP地址库采集器c#代码,有需要的朋友可以参考一下. 最近做一个项目,功能类似于CNZZ站长统计功能,要求显示Ip所在的省份市区/提供商等信息.网上的Ip纯真数据库,下载下来一看 ...
- 淘宝IP地址库API接口(PHP)通过ip获取地址信息
淘宝IP地址库网址:http://ip.taobao.com/ 提供的服务包括: 1. 根据用户提供的IP地址,快速查询出该IP地址所在的地理信息和地理相关的信息,包括国家.省.市和运营商. 2. 用 ...
- 淘宝IP地址库采集
作者:阿宝 更新:2016-08-31 来源:彩色世界(https://blog.hz601.org/2016/08/31/taobao-ip-sniffer/index.html) 简述 当初选择做 ...
- 淘宝IP地址库API地址
淘宝IP地址库:http://ip.taobao.com/instructions.php 接口说明 1. 请求接口(GET): http://ip.taobao.com/service/getI ...
- 淘宝IP地址库采集器c#
个人原创.欢迎转载.转载请注明出处.http://www.cnblogs.com/zetee/articles/3482085.html 采集器概貌,如下: 最近做一个项目,功能类似于CNZZ站长统计 ...
随机推荐
- Appfuse:扩展自己的GenericManager
通过代码生成机制的appfuse访问数据都通过GenericManager来实现,GenericManager默认提供了以下几个方法: package org.appfuse.service; imp ...
- yii2分页扩展之实现跳转到具体某页
作者:白狼 出处:http://www.manks.top/yii2_linkpager_widget.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文 ...
- 自动将指定目录下面的文件转换为UTF-8
using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...
- shell 1>&2 2>&1 &>filename重定向的含义和区别
当初在shell中, 看到">&1"和">&2"始终不明白什么意思.经过在网上的搜索得以解惑.其实这是两种输出. 在 shell 程 ...
- WPF Path
在WPF中,自定义控件,经常用到Path. Path可以绘制多边形.边框.线条.简单的图标等. 1.Xaml中用法: <Path Stroke="DodgerBlue" St ...
- android EditText 默认情况下不获取焦点(不弹出输入框)
可以在EditText前面放置一个看不到的LinearLayout,让它率先获取焦点: <LinearLayout android:focusable="true" andr ...
- 域普通用户执行金蝶K/3权限不够解决方法
一.问题 公司财务部的机器加入域后,用户一直授予本地管理员的权限,主管坚持要撤销管理员权限,而金蝶K3没管理员权限又无法执行. 报错信息为“注册表许可权不够,请参考安装目录的帮助档案进行许可权的配置. ...
- 浅谈Virtual Machine Manager(SCVMM 2012) cluster 过载状态检测算法
在我们使用scvmm2012的时候,经常会看到群集状态变成了这样 点开看属性后,我们发现是这样 . 发现了吗?Over-committed,如果翻译过来就是资源过载,或者说资源过量使用了,那么这个状态 ...
- 常用的14种HTTP状态码速查手册
分类 1xx \> Information(信息) // 接收的请求正在处理 2xx \> Success(成功) // 请求正常处理完毕 3xx \> Redirection(重定 ...
- webform开发基础
ASP.NET WebForm C/S(Client/Server):客户端服务器 B/S(Browser/Server):浏览器服务器 C/S和B/S的区别: 首先必须强调的是C/S和B/S并没有本 ...