在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
<?php function getClientIp($type = 0,$adv=false) { $type = $type?1:0; static $ip = NULL; if($ip !== NULL) return $ip[$type]; if($adv){ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } $long = sprintf("%u",ip2long($ip)); $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); return $ip[$type]; } //获取省 function getIpLocal($ip){ if($ip==""||$ip==null) $ip=getClientIp(); $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=".$ip; $json = json_decode(file_get_contents($url)); $city=$json->city; $city=str_replace('市','',$city); $city = iconv("utf-8","gb2312",$city);//字符串转码 $province=$json->province; $province=str_replace('省','',$province); $province = iconv("utf-8","gb2312",$province);//字符串转码 return $province; } //获取市 function getIpLocal_city($ip){ if($ip==""||$ip==null) $ip=getClientIp(); $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=".$ip; $json = json_decode(file_get_contents($url)); $city=$json->city; $city=str_replace('市','',$city); $city = iconv("utf-8","gb2312",$city);//字符串转码 $province=$json->province; $province=str_replace('省','',$province); $province = iconv("utf-8","gb2312",$province);//字符串转码 return $city; } /*$diqu=getIpLocal("14.215.177.37");*/ //获取省 $diqu=getIpLocal(getClientIp()); //获取市 $diqu_city=getIpLocal_city(getClientIp()); //判断省 if($diqu=='北京'||$diqu=='江苏'){ echo "window.location.href='http://www.baidu.com';"; } //判断市 if($diqu_city=='北京'){ echo "window.location.href='http://www.baidu.com';"; } //判断ip段 if($ip==""||$ip==null){ $ip=getClientIp(); } $arrayip = array('180.76.14.*','180.97.79.*','60.194.2.*');//ip段 $ipregexp = implode('|', str_replace( array('*','.'), array('\d+','\.') ,$arrayip) ); if(preg_match("/^(".$ipregexp.")$/", $ip)==1){ echo "window.location.href='http://www.baidu.com';"; } ?> 由于http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪接口目前用不了 ,下面用淘宝提供的接口 <?php function getClientIp($type = 0,$adv=false) { $type = $type?1:0; static $ip = NULL; if($ip !== NULL) return $ip[$type]; if($adv){ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } $long = sprintf("%u",ip2long($ip)); $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); return $ip[$type]; } //获取省 function getIpLocal($ip){ if($ip==""||$ip==null) $ip=getClientIp(); $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $content =file_get_contents($url); $arr = json_decode($content,true); return $arr["data"]["region"]; } //获取市 function getIpLocal_city($ip){ if($ip==""||$ip==null) $ip=getClientIp(); $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $content =file_get_contents($url); $arr = json_decode($content,true); return $arr["data"]["city"]; } /*$diqu=getIpLocal("14.215.177.37");*/ //获取省 $diqu=getIpLocal(getClientIp()); //获取市 $diqu_city=getIpLocal_city(getClientIp()); //判断省 if($diqu=='北京'|| $diqu=='福建'){ echo "window.location.href='http://www.baidu.com';"; } //判断市 if($diqu_city=='北京' || $diqu_city=='上海' || $diqu_city=='广州'|| $diqu_city=='深圳' || $diqu_city=='杭州'){ echo "window.location.href='http://www.baidu.com';"; } //判断ip段 if($ip==""||$ip==null){ $ip=getClientIp(); } $arrayip = array('180.76.14.*','180.97.79.*','60.194.2.*');//ip段 $ipregexp = implode('|', str_replace( array('*','.'), array('\d+','\.') ,$arrayip) ); if(preg_match("/^(".$ipregexp.")$/", $ip)==1){ echo "window.location.href='http://www.baidu.com';"; } ?>
|
2022-07-18
2022-08-16
2022-11-06
2022-08-18
2022-08-15
请发表评论