<?php
/*$ip=real_ip();
$url='http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.$ip;
$content=fopen_url($url);
$Exp='/country":"(.*?)","province":"(.*?)","city":"(.*?)","district":"","isp":"(.*?)","type/s';
$content=unicodeDecode( $content );
if(preg_match($Exp,$content,$matche)){
echo 'Hello,来自'.$matche[1].$matche[2].$matche[3].'的朋友.';
}elseif(preg_match('/"ret":-1,"ip":"(.*?)"/',$content,$matche)){
echo '您使用的是局域网,局域网IP为'.$matche[1];
}else{
echo '你来自火星吧。';
}*/
/**
?*
?*/
function ipFunGetCityNameById(){
??? $url='http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.ipFunReal_ip();
??? $content=ipFunFopen_url($url);
??? $Exp='/country":"(.*?)","province":"(.*?)","city":"(.*?)","district":"","isp":"(.*?)","type/s';
??? $content=ipFunUnicodeDecode( $content );
??? if(preg_match($Exp,$content,$matche)){
??? ??? return $matche[3];
??? }else
??? ??? return "";
}
?
?
//Curl 获取网址内容
function ipFunFopen_url($url)
{
??? if (function_exists('file_get_contents')) {
??????? $file_content = @file_get_contents($url);
??? } elseif (ini_get('allow_url_fopen') && ($file = @fopen($url, 'rb'))){
??????? $i = 0;
??????? while (!feof($file) && $i++ < 1000) {
??????????? $file_content .= strtolower(fread($file, 4096));
??????? }
??????? fclose($file);
??? } elseif (function_exists('curl_init')) {
??????? $curl_handle = curl_init();
??????? curl_setopt($curl_handle, CURLOPT_URL, $url);
??????? curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2);
??????? curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1);
??????? curl_setopt($curl_handle, CURLOPT_FAILONERROR,1);
??????? curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Trackback Spam Check');
??????? $file_content = curl_exec($curl_handle);
??????? curl_close($curl_handle);
??? } else {
??????? $file_content = '';
??? }
??? return $file_content;
}
?
function ipFunUnicodeDecode($content)
{
??? // 转换编码,将Unicode编码转换gb2312编码
??? $pattern = '/(\\\u([\w]{4}))/i';
??? preg_match_all($pattern, $content, $matches);
??? if (!empty($matches))
??? {
??????? for ($j = 0; $j < count($matches[0]); $j++)
??????? {
??????????? $str = $matches[0][$j];
??????????? if (strpos($str, '\\u') === 0)
??????????? {
??????????????? $code = base_convert(substr($str, 2, 2), 16, 10);
??????????????? $code2 = base_convert(substr($str, 4), 16, 10);
?
??????????????? $c = chr($code).chr($code2);
??? ??? ??? ??? $c=mb_convert_encoding($c, "UTF-8", 'UCS-2');
??????????????? //$c = iconv('UCS-2', 'gb2312', $c);
??? ??? ??? ??? $content=str_replace($matches[0][$j],$c,$content);
??????????? }
??????????? else
??????????? {
??????????????? $content .= $str;
??????????? }
??????? }
??? }
??? return $content;
}
?
function ipFunReal_ip()
{
??? static $realip = NULL;
?
??? if ($realip !== NULL)
??? {
??????? return $realip;
??? }
?
??? if (isset($_SERVER))
??? {
??????? if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
??????? {
??????????? $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
?
??????????? /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */
??????????? foreach ($arr AS $ip)
??????????? {
??????????????? $ip = trim($ip);
?
??????????????? if ($ip != 'unknown')
??????????????? {
??????????????????? $realip = $ip;
?
??????????????????? break;
??????????????? }
??????????? }
??????? }
??????? elseif (isset($_SERVER['HTTP_CLIENT_IP']))
??????? {
??????????? $realip = $_SERVER['HTTP_CLIENT_IP'];
??????? }
??????? else
??????? {
??????????? if (isset($_SERVER['REMOTE_ADDR']))
??????????? {
??????????????? $realip = $_SERVER['REMOTE_ADDR'];
??????????? }
??????????? else
??????????? {
??????????????? $realip = '0.0.0.0';
??????????? }
??????? }
??? }
??? else
??? {
??????? if (getenv('HTTP_X_FORWARDED_FOR'))
??????? {
??????????? $realip = getenv('HTTP_X_FORWARDED_FOR');
??????? }
??????? elseif (getenv('HTTP_CLIENT_IP'))
??????? {
??????????? $realip = getenv('HTTP_CLIENT_IP');
??????? }
??????? else
??????? {
??????????? $realip = getenv('REMOTE_ADDR');
??????? }
??? }
?
??? preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
??? $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
?
??? return $realip;
}
详细解决方案
挪用SINA IP地址库取用户所在城市及地区 PHP版
热度:28 发布时间:2016-04-28 22:57:42.0
相关解决方案
- cmd输入telnet smtp.sina.com25展示telnet不是内部命令
- sina editor编辑器无法下传附件和图片
- 新浪的博客地址http://blog.sina.com.cn/u/1214132890是什么技术?该怎么解决
- sohu sina 最上面的登录框是如何做出来的
- 铁路网站为什么不请问请问腾讯、百度、sina、淘宝
- 关于在本地配置一个www.sina.com和music.sina.com的域名的有关问题
- 急招技术开发人员请把简历发到gamer0001@sina.com
- Gesture手势 转从http://blog.sina.com.cn/s/blog_8a6c97b5010106zq.html
- BMP文件加载研讨(转http://blog.sina.com.cn/s/blog_5da62ae00100pyls.html)
- Struts2中OGNL的学习(转从http://blog.sina.com.cn/s/blog_5dc034a30100nx7n.html)
- BMP资料加载探讨(转http://blog.sina.com.cn/s/blog_5da62ae00100pyls.html)
- Sina App 小使用
- 之前的几篇有关问题记录在新浪博客http://blog.sina.com.cn/peanutlu
- 怎么实现http://iask.sina.com.cn/b/8938481.html里的效果
- javamail smtp.sina.com.cn 的连接有关问题
- 谁知道 新浪 的新闻页面是如何做的! www.sina.com.cn
- 小弟我的blog: http://blog.sina.com.cn/mickeyzhouyou
- 用JAVA发送邮件 注:(原稿来自http://blog.sina.com.cn/liuanzhi)
- 小弟我想请教各位大侠为什么下面的这个发邮件的程序只有用 sina 的用户好使,别的都不好用呢
- 像Google Baidu Sina 163这些搜索引擎和门户网站都用什么数据库解决方法
- 像Google Baidu Sina 163这些搜索引擎跟门户网站都用什么数据库
- 像Google Baidu Sina 163这些搜索引擎和门户网站都用什么数据库解决思路
- 小弟我(在局域网中)用IE访问http://www.sina.com.cn。然后看到网页。这途中,网络层的包是怎么传递的
- 小弟我向www.sina.com.cn发出一个http get请求,请求IP数据包的路径与sina返回数据的路径一样吗
- 有办法知道www.sina.com.cn一台WEB服务器的MAC地址吗? 为什么?该怎么处理
- sina weibo有关问题,小弟我想让用户不登陆就可以看见一些微薄
- SUMO教程和MeanShift算法图片不可见的,请移步至本人的新浪博客。http://blog.sina.com.cn/qtluyixiao。抱歉给大家带来的不便。
- 微博分享不成功 Failed to find provider info for com.sina.weibo.sdkProvider
- LoadXML的正确使用(原文:http://blog.sina.com.cn/s/blog_68530d690100mlcp.html)
- Sina API OAuth