";
$sb = "shisb";
//var_dump($str);
// echo "获取get变量=",Request::instance()->get('name'); // 获取get变量
// echo "获取get某个变量name=",Request::instance()->get('name'); // 获取get变量
//var_dump(getSdkOpenNumber("天津|北京|河北|山西|内蒙古|辽宁|吉林|黑龙江|上海|江苏|浙江|安徽|福建|江西|山东|河南|湖北|湖南|广东|广西|海南|四川|贵州|云南|西藏|陕西|甘肃|青海|宁夏|新疆|重庆|","北京","天津","100018"));
//echo getSdkOpenNumber("北京|天津|河北|山西|内蒙古|辽宁|吉林|黑龙江|上海|江苏|浙江|安徽|福建|江西|山东|河南|湖北|湖南|广东|广西|海南|四川|贵州|云南|西藏|陕西|甘肃|青海|宁夏|新疆|重庆|","北京","天津","100018");
//function getSdkOpenNumber($shield_province,$belonging_provincez,$ip_province,$source_id){
//echo "归属地为:".getMobileArea($tempIMSI)."-----City=".getMoblieCity($tempIMSI);
echo "北京判断","
";
//$shield_Special_Number_province,$belonging_province,$ip_province,$source_id,$timeHour,$ip_city,$belong_city)
if(!getSdkOpenNumbertheSpecialP("|01","广东","江西","100018","18","北京","天津")){
echo "广东屏蔽--返回0","
";
}else{
echo "北京不屏蔽--返回2","
";
}
// echo "长沙","
";
// if(!getSdkOpenNumbertheSpecialP("08","长沙","长沙","111","11","长沙","长沙")){
// echo "---长沙屏蔽","
";
// }
// echo "归属地大连","
"; //归属地大连
// if(!getSdkOpenNumbertheSpecialP("14","北京","北京","111","11","北京","大连")){
// echo "---归属地大连屏蔽","
";
// }
// echo "归属地石家庄","
";
// if(!getSdkOpenNumbertheSpecialP("18","北京","北京","111","11","北京","石家庄")){
// echo "---归属地石家庄屏蔽","
";
// }
// echo "苏州IP 归属地梧州 时间段外","
";
// if(!getSdkOpenNumbertheSpecialP("15","浙江","浙江","111","08","苏州","梧州")){
// echo "---苏州IP 归属地梧州 时间段外屏蔽","
";
// }
// echo "归属地天津 时间段内","
";
// if(!getSdkOpenNumbertheSpecialP("05","浙江","浙江","111","11","苏州","天津")){
// echo "---天津呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃 时间段内屏蔽","
";
// }
function getSdkOpenNumber($shield_province,$belonging_provincez,$ip_province,$source_id){
$return = array(true,false,false);
if($shield_province == ""){
return $return;
}
$shield_province = explode(":",$shield_province);
$tempNI = 0;
foreach( $shield_province as $vale){
// if($vale == ""){
// $return[$tempNI] = false;
// $tempNI++;
// continue;
// }
/*
if(500000<$source_id && $source_id<600000){
if ( !isInString($vale,$belonging_provincez) ){
$return[$tempNI] = true;
}else{
$return[$tempNI] = false;
}
}else{
if ( !isInString($vale,$belonging_provincez) && !isInString($vale,$ip_province)){
$return[$tempNI] = true;
}else{
$return[$tempNI] = false;
}
}*/
if ( !isInString($vale,$belonging_provincez) ){ //
$return[$tempNI] = true;
}else{
$return[$tempNI] = false;
}
$tempNI++;
}
return $return;
}
function getSdkOpenNumbertheSpecialP($shield_Special_Number_province,$belonging_province,$ip_province,$source_id,$timeHour,$ip_city,$belong_city){
$tempReturn = true;
$shield_Special_City = array(
"上海","重庆","天津",
"南京","杭州","长沙","武汉","合肥",
"厦门","福州","沈阳","大连","苏州",
"成都","海口","石家庄"
);
$shield_Special_City_Vlues = array(
"03","04","05",
"06","07","08","09","10",
"11","12","13","14","15",
"16","17","18"
);
$count = 0;
foreach($shield_Special_City_Vlues as $tempVlues){
if(isInString($shield_Special_Number_province,$tempVlues)){
if((isInString($belong_city,$shield_Special_City[$count]) || isInString($ip_city,$shield_Special_City[$count])) && isInString("09|10|11|12|13|14|15|16|17|18|19|20|21",$timeHour)){
$tempReturn = false;
}
}
$count++;
}
//未来可能改18-06-04 广东-OPPO渠道 全周屏蔽, 北京 全周全屏 。 其它[包括广东] 周一至 周五 屏蔽 。
if(isInString($shield_Special_Number_province,"01")){
if((isInString($belonging_province,"广东") || isInString($ip_province,"广东")) && isInString("09|10|11|12|13|14|15|16|17|18|19|20|21",$timeHour)){
$tempReturn = false;
}
}
if(isInString($shield_Special_Number_province,"02")){
if((isInString($belonging_province,"北京") || isInString($ip_province,"北京")) && isInString("00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23",$timeHour)){
$tempReturn = false;
}
}
return $tempReturn;
}
function getMoblieCity($tempIMSI){
$tempCity = "无";
$ResultCountry = getMobileArea($tempIMSI);
$locationShen = strpos($ResultCountry," ");
$locationShi = strpos($ResultCountry,"市");
if ($locationShen){
if ($locationShi){
$tempCity = substr($ResultCountry,$locationShen+1,$locationShi-$locationShen-1);
}else{
//没有“市”--什么州 自治区
if(substr($ResultCountry,$locationShen+1) !=""){
$tempCity = substr($ResultCountry,$locationShen+1);
}
}
}else{
$tempCity = substr($ResultCountry,0);
}
return $tempCity;
}
function getMobileArea($tempImsi){
$zhengzeArrayList = array(
"^46001(\\d{3})(\\d)[0,1]\\d+^",
"^46001(\\d{3})(\\d)9\\d+^",
"^46001(\\d{3})(\\d)2\\d+^",
"^460020(\\d)(\\d{3})\\d+^",
"^46000(\\d{3})([5,6,7,8,9])\\d+^",
"^46000(\\d{3})([0,1,2,3,4])(\\d)\\d+^",
"^460023(\\d)(\\d{3})\\d+^",
"^460021(\\d)(\\d{3})\\d+^",
"^460022(\\d)(\\d{3})\\d+^",
"^46001(\\d{3})(\\d)4\\d+^",
"^46001(\\d{3})(\\d)3\\d+^",
"^460077(\\d)(\\d{3})\\d+^",
"^460028(\\d)(\\d{3})\\d+^",
"^460029(\\d)(\\d{3})\\d+^",
"^460079(\\d)(\\d{3})\\d+^",
"^46001(\\d{3})(\\d)5\\d+^",
"^46001(\\d{3})(\\d)6\\d+^",
"^460027(\\d)(\\d{3})\\d+^",
"^460078(\\d)(\\d{3})\\d+^",
"^460070(\\d)(\\d{3})\\d+^", //
"^46001(\\d{3})(\\d)8\\d+^", //
"^460075(\\d)(\\d{3})\\d+^",
"^46001(\\d{3})(\\d)7\\d+^",
"^460026(\\d)(\\d{3})\\d+^",
"^460025(\\d)(\\d{3})\\d+^",
"^460024(\\d)(\\d{3})\\d+^",
//电信的,下面的还没有找到规则
"^46003(\\d)(\\d{3})7\\d+^",
"^46003(\\d)(\\d{3})8\\d+^",
"^46003(\\d)(\\d{3})9\\d+^"
);
$headMobileValueList = array(
"130",
"131",
"132",
"134",
"13",
"13",
"150",
"151",
"152",
"155",
"156",
"157",
"158",
"159",
"147",
"185",
"186",
"187",
"188",
"170",
"170",
"178",
"145",
"182",
"183",
"184",
//电信的
"180",
"153",
"189",
);
$count = 0;
//1 2 3 5 10 11 16 17 21 23
foreach($zhengzeArrayList as $zhengze){
if(8 == 9){
echo "PHP是世界上最好的语言??";
}
//echo "
","count==".$count;
if($count == "0" ||$count == "1" ||$count == "2" ||$count == "9" ||$count == "10" ||$count == "15" ||$count == "16"||$count == "20"||$count == "22"){
$tempMobile = getPhoneNum($headMobileValueList[$count],$zhengze,$tempImsi,2,1);
if( $tempMobile !=""){
break;
}
//$count++;
}else{
//特殊处理
if($count == "4"){
if(preg_match($zhengze,$tempImsi,$ttt)){
$tempMobile = $headMobileValueList[$count].$ttt[2]."0".$ttt[1];
if( $tempMobile !=""){
break;
}
}
}else{
if($count == "5"){
if(preg_match($zhengze,$tempImsi,$ssb)){
//return "13"+(Integer.parseInt(result[1])+5)+result[2]+result[0];
$tmepV = $ssb[2]+5;
$tempMobile = $headMobileValueList[$count].$tmepV.$ssb[3].$ssb[1];//+5.$ssb[3].$ssb[1]
if( $tempMobile !=""){
break;
}
}
}else{
//正常
$tempMobile = getPhoneNum($headMobileValueList[$count],$zhengze,$tempImsi,1,2);
if( $tempMobile !=""){
break;
}
}
}
}
$count++;
}
//echo "tempMobile=".$tempMobile;
//连接数据库--在表中查询
$link = mysql_connect('localhost:3306','root','zz753951');
if (!$link) {
die(iconv("GB2312","UTF-8",'连接服务器失败:'."
"). mysql_error());
}
mysql_query("set names 'utf8'");
mysql_select_db("door", $link);
$query = "SELECT `mobile_area` FROM `rdms_mobile_area` WHERE `mobile_number` = '$tempMobile' ";
$result = mysql_query($query);
$temparry = mysql_fetch_array($result);
$ResultArea = $temparry['mobile_area'];
if($ResultArea == ""){
return "无";
}
return $ResultArea;
}
//根据正则表达式获取手机前7位 参数1头三位,2.正则3.imsi4.5 连接位
function getPhoneNum($headPhonenumer,$zhengze,$tempIMSI,$first,$last){
if(preg_match($zhengze,$tempIMSI,$ttt)){
var_dump($ttt);
$tempStr = $headPhonenumer.$ttt[$first].$ttt[$last];
return $tempStr.$ttt[$last];
}else{
return "";
}
}
//echo substr($tempICCID,4,1);
// Step2.若该用户为联通用户,则判断IMSI第十位:若为0 或1,则为130;若为2,则为132;若为3,则为156;若为4,则为
// 155;若为6,则为186;若为9,则为131:
// Step3.若该用户为联通用户,则手机号的第四到七位分别 对应该用户IMSI的第九位、第六位、第七位、第八位;
// Step4.若该用户为移动用户,且IMSI的第五位为0,则IM— SI的第九位数字即为该用户手机号码的第三位数字(前两位为
// 13),若IMSI第九位为0—4,则该用户手机号码第三位为1MSI 的第九位数字,手机号码第四位为0,手机号码第五位到第七位 分别为IMSI的第六位、第七位和第八位;
// Step5.若该用户为移动用户,且IMSI的第五位为0,则IM— sI的第九位数字即为该用户手机号码的第三位数字(前两位为
// 13),若IMSI第九位为5-9,则该用户手机号码第三位为1MSI 的第九位数字,手机号码第四位为IMSI的第十位数字,手机号 码第五位到第七位分别为IMSI的第六位、第七位和第八位:
// Step6.若该用户为移动用户,且IMSI的第五位为2,则继
// 续判断IMSI的第九位:若为0,则为134;若为1,则为151;若 为2,则为152;若为3,则为150;若为7,则为157;若为8,则为
// 188;若为9,则为147。该用户手机号码的第四位到第七位分别
// 对应IMSI的第七位到第十位;
// Step7.若该用户为移动用户,且IMSI的第五位为7,则继
// 续判断IMSI的第六位:若为7,则为157;若为8,则为188;若
// 为9,则为147。该用户手机号码的第四位到第七位分别对应 IMSI的第七位到第十位。
//约定==1移动2联通3电信
// switch(substr($tempICCID,4,1)){
// case 1:
// case 6:
// $tempOP = 2;
// substr($tempICCID,9,1)
// break;
// case 0:
// case 2:
// case 7:
// $tempOP = 1;
// break;
// default:
// $tempOP = 3;
// break;
// }
//$tmepOP = substr($tempICCID,4,1);
// $sb = new GetPhoneNumer();
// echo "eeeee".$sb->compile("^46001(\\d{3})(\\d)[0-1]\\d+^","460012351994518")."=====","
";
// echo "rrrrrrrr".$sb->compile("^46001^","37460012351994518")."-------","
";
// var_dump($sb->compile("^46001(\\d{3})(\\d)[0,1]\\d+^","460012351994518"));
//根据IMSI获取手机号码段(7位)
class GetPhoneNumer{
//$tempCompile = array();
function getPhoneSevenNumber($imsi) {
// TODO Auto-generated method stub
$s130 = "^46001(\\d{3})(\\d)[0,1]\\d+";
$s131 = "^46001(\\d{3})(\\d)9\\d+";
$s132 = "^46001(\\d{3})(\\d)2\\d+";
$s134 = "^460020(\\d)(\\d{3})\\d+";
$s13x0 = "^46000(\\d{3})([5,6,7,8,9])\\d+";
$s13x = "^46000(\\d{3})([0,1,2,3,4])(\\d)\\d+";
$s150 = "^460023(\\d)(\\d{3})\\d+";
$s151 = "^460021(\\d)(\\d{3})\\d+";
$s152 = "^460022(\\d)(\\d{3})\\d+";
$s155 = "^46001(\\d{3})(\\d)4\\d+";
$s156 = "^46001(\\d{3})(\\d)3\\d+";
$s157 = "^460077(\\d)(\\d{3})\\d+";
$s158 = "^460028(\\d)(\\d{3})\\d+";
$s159 = "^460029(\\d)(\\d{3})\\d+";
$s147 = "^460079(\\d)(\\d{3})\\d+";
$s185 = "^46001(\\d{3})(\\d)5\\d+";
$s186 = "^46001(\\d{3})(\\d)6\\d+";
$s187 = "^460027(\\d)(\\d{3})\\d+";
$s188 = "^460078(\\d)(\\d{3})\\d+";
$s1705 = "^460070(\\d)(\\d{3})\\d+";
$s170x = "^46001(\\d{3})(\\d)8\\d+";
$s178 = "^460075(\\d)(\\d{3})\\d+";
$s145 = "^46001(\\d{3})(\\d)7\\d+";
$s182 = "^460026(\\d)(\\d{3})\\d+";
$s183 = "^460025(\\d)(\\d{3})\\d+";
$s184 = "^460024(\\d)(\\d{3})\\d+";
//电信的,下面的还没有找到规则
$s180 = "^46003(\\d)(\\d{3})7\\d+";
$s153 = "^46003(\\d)(\\d{3})8\\d+";
$s189 = "^46003(\\d)(\\d{3})9\\d+";
// String[] result = compile($s130,$imsi);
// if(result != null && result.length==2){
// return "130"+result[1]+result[0];
// }
// result = compile($s131,$imsi);
// if(result != null && result.length==2){
// return "131"+result[1]+result[0];
// }
// result = compile($s132,$imsi);
// if(result != null && result.length==2){
// return "132"+result[1]+result[0];
// }
// result = compile($s134,$imsi);
// if(result != null && result.length==2){
// return "134"+result[0]+result[1];
// }
// result = compile($s13x0,$imsi);
// if(result != null && result.length==2){
// return "13"+result[1]+"0"+result[0];
// }
// result = compile($s13x,$imsi);
// if(result != null && result.length==3){
// return "13"+(Integer.parseInt(result[1])+5)+result[2]+result[0];
// }
// result = compile($s150,$imsi);
// if(result != null && result.length==2){
// return "150"+result[0]+result[1];
// }
// result = compile($s151,$imsi);
// if(result != null && result.length==2){
// return "151"+result[0]+result[1];
// }
// result = compile($s152,$imsi);
// if(result != null && result.length==2){
// return "152"+result[0]+result[1];
// }
// result = compile($s155,$imsi);
// if(result != null && result.length==2){
// return "155"+result[1]+result[0];
// }
// result = compile($s156,$imsi);
// if(result != null && result.length==2){
// return "156"+result[1]+result[0];
// }
// result = compile($s157,$imsi);
// if(result != null && result.length==2){
// return "157"+result[0]+result[1];
// }
// result = compile($s158,$imsi);
// if(result != null && result.length==2){
// return "158"+result[0]+result[1];
// }
// result = compile($s159,$imsi);
// if(result != null && result.length==2){
// return "159"+result[0]+result[1];
// }
// result = compile($s147,$imsi);
// if(result != null && result.length==2){
// return "147"+result[0]+result[1];
// }
// result = compile($s185,$imsi);
// if(result != null && result.length==2){
// return "185"+result[1]+result[0];
// }
// result = compile($s186,$imsi);
// if(result != null && result.length==2){
// return "186"+result[1]+result[0];
// }
// result = compile($s187,$imsi);
// if(result != null && result.length==2){
// return "187"+result[0]+result[1];
// }
// result = compile($s188,$imsi);
// if(result != null && result.length==2){
// return "188"+result[0]+result[1];
// }
// result = compile($s1705,$imsi);
// if(result != null && result.length==2){
// return "170"+result[0]+result[1];
// }
// result = compile($s170x,$imsi);
// if(result != null && result.length==2){
// return "170"+result[1]+result[0];
// }
// result = compile($s178,$imsi);
// if(result != null && result.length==2){
// return "178"+result[0]+result[1];
// }
// result = compile($s145,$imsi);
// if(result != null && result.length==2){
// return "145"+result[1]+result[0];
// }
// result = compile($s182,$imsi);
// if(result != null && result.length==2){
// return "182"+result[0]+result[1];
// }
// result = compile($s183,$imsi);
// if(result != null && result.length==2){
// return "183"+result[0]+result[1];
// }
// result = compile($s184,$imsi);
// if(result != null && result.length==2){
// return "184"+result[0]+result[1];
// }
// result = compile($s180,$imsi);
// if(result != null && result.length==2){
// return "180"+result[0]+result[1];
// }
// result = compile($s153,$imsi);
// if(result != null && result.length==2){
// return "153"+result[0]+result[1];
// }
// result = compile($s189,$imsi);
// if(result != null && result.length==2){
// return "189"+result[0]+result[1];
// }
// return "";
}
function compile($reg,$imsi){
// Pattern pattern = Pattern.compile(reg);
// Matcher matcher = pattern.matcher(imsi);
// $tempResult = array();
//返回 pattern 的匹配次数。 它的值将是 0 次(不匹配)或 1 次,因为 preg_match() 在第一次匹配后 将会停止搜索。
//preg_match_all() 不同于此,它会一直搜索subject 直到到达结尾。 如果发生错误preg_match()返回 FALSE。
$tempCompile = preg_match($reg,$imsi,$tt);
echo "qqq";
if($tempCompile){
echo "wwww";
$tempResult= $tt[0];
return $tempResult;
}
return "000";
// if(matcher.find()){
// String[] sArr = new String[matcher.groupCount()];
// for(int i=0;i getIP($clientIp);
// $ip_province = $nowIpProvinceAndCity -> Province;
// $ip_city = $nowIpProvinceAndCity -> City;
// $tempArry2 = explode(".",$clientIp);
// for($i=0;$i<4;$i++){
// $ip .= zeroFillLeft($tempArry2[$i] ,3);
// }
// //$get_data = file_get_contents("php://input");
// echo "get=".$_GET['get'].'
';
// echo "ip="."$clientIp"."--ip_province=".$ip_province."--ip_city="."$ip_city".'
';
// $t=time();//为这次访问的时间数据 date('Y-m-d H:i:s',"1228348800");
// $tempCheckDate = "2018/07/13";
// if('1' > $tempCheckDate){
// $checkDate = "1";
// $tempCheckDate = date("Y-m",$t);
// }else{
// $tempabc = (strtotime($tempCheckDate." 12:00:00"));
// $tempCheckDate = date("Y-m-d",$tempabc);
// $checkDate = "`日期` = '$tempCheckDate'";//1移动 2联通 3电信 or die("Error in query: $query. ".mysql_error())
// }
// var_dump ($tempCheckDate);
// if($tempCheckDate >= date("Y-m-d",(strtotime("2018/07/12"." 12:00:00")))){
// echo "大于";
// }else{
// echo "小鱼";
// }
// $tBeiJing = (strtotime($tempCheckDate." 12:00:00"));
// //echo $ProductID.$chanel.$checkDate.$op;echo '
';
// echo $tBeiJing;
// $willLikeDb = date("ym",$tBeiJing);
// $willLikeDb = $willLikeDb."激活数据";//echo $willLikeDb;
// class getIPMiLi {
// var $Province; //IP数据库文件句柄
// var $City; //第一条索引
// var $nowIP;
// public $zizhiquList = array(
// "宁夏","新疆","西藏","广西"
// );
// function getIP($nowClientIP){
// $tempProvince = "无";
// $tempCity = "无";
// //之前的定位方法
// // $ip = new ip();
// // $addr = $ip -> ip2addr($nowClientIP);
// //更改为数据库查询
// $tempIp = new IPfromeSql();
// $ResultCountry = $tempIp -> getCountry($nowClientIP);
// $locationShen = strpos($ResultCountry,"省");
// $locationShi = strpos($ResultCountry,"市");
// if ($locationShen){
// $tempProvince = substr($ResultCountry,0,$locationShen);
// if ($locationShi){
// $tempCity = substr($ResultCountry,$locationShen+3,$locationShi-$locationShen-3);
// }
// }else{
// if ($locationShi){
// $tempProvince = substr($ResultCountry,0,$locationShi);
// $tempCity = substr($ResultCountry,0,$locationShi);
// }
// if (strpos("=-=".$ResultCountry,"内蒙古")){
// $tempProvince = "内蒙古";
// if ($locationShi){
// $tempCity = substr($ResultCountry,9,$locationShi-9);
// }
// }
// for($i=0;$i<4;$i++){
// $zizhiqu =strpos("=-=".$ResultCountry,$this->zizhiquList[$i]);
// $locationShi = strpos($ResultCountry,"市");
// if ($zizhiqu){
// $tempProvince = $this->zizhiquList[$i];
// if ($locationShi){
// $tempCity = substr($ResultCountry,$zizhiqu+3,$locationShi-$zizhiqu-3);
// }
// }
// }
// }
// if ($tempProvince == "无" && $tempProvince == "无"){
// if($locationShen){$tempProvince = $tempCountry;}else{$tempProvince = "无";}
// }
// $this->Province = $tempProvince;
// $this->City = $tempCity;
// echo '
',$tempProvince;
// echo '
',$tempCity,'
';
// }
// }
// class IPfromeSql{
// function getCountry($ip){
// // if(!$this -> checkIp($ip)){
// // return false;
// // }
// $ipNumber = ip2long($ip);
// //当ip地址比较大时,ip2long会出现负数-----32位机器
// if($ipNumber < 0){
// $ipNumber = sprintf("%u",ip2long($ip));
// }
// //连接数据库--在iptable表中查询
// $link = mysql_connect('localhost:3306','root','zz753951');
// if (!$link) {
// die(iconv("GB2312","UTF-8",'连接服务器失败:'."
"). mysql_error());
// }
// mysql_query("set names 'utf8'");
// mysql_select_db("door", $link);
// //$query = "SELECT * FROM `iptable` WHERE `StartIPNum` <= '$ipNumber' ORDER BY `StartIPNum` DESC limit 1";
// $query = "SELECT `Country` FROM `iptable` WHERE `ID`=(SELECT `ID` FROM `iptable` WHERE `StartIPNum` >= '$ipNumber' limit 1)+1";
// $result = mysql_query($query);
// //查询为空??
// $temparry = mysql_fetch_array($result);
// $ResultCountry = $temparry['Country'];
// return $ResultCountry;
// }
// //检查IP合法性
// function checkIp($ip) {
// $arr = explode('.',$ip);
// if(count($arr) !=4 ) {
// return false;
// } else {
// for ($i=0; $i < 4; $i++) {
// if ($arr[$i] <'0' || $arr[$i] > '255') {
// return false;
// }
// }
// }
// return true;
// }
// }
// class ip {
// var $fh; //IP数据库文件句柄
// var $first; //第一条索引
// var $last; //最后一条索引
// var $total; //索引总数
// //构造函数
// function __construct() {
// $this->fh = fopen('qqwry.dat', 'rb'); //qqwry.dat文件
// $this->first = $this->getLong4();
// $this->last = $this->getLong4();
// $this->total = ($this->last - $this->first) / 7; //每条索引7字节
// }
// //检查IP合法性
// function checkIp($ip) {
// $arr = explode('.',$ip);
// if(count($arr) !=4 ) {
// return false;
// } else {
// for ($i=0; $i < 4; $i++) {
// if ($arr[$i] <'0' || $arr[$i] > '255') {
// return false;
// }
// }
// }
// return true;
// }
// function getLong4() {
// //读取little-endian编码的4个字节转化为长整型数
// $result = unpack('Vlong', fread($this->fh, 4));
// return $result['long'];
// }
// function getLong3() {
// //读取little-endian编码的3个字节转化为长整型数
// $result = unpack('Vlong', fread($this->fh, 3).chr(0));
// return $result['long'];
// }
// //查询信息
// function getInfo($data = "") {
// $char = fread($this->fh, 1);
// while (ord($char) != 0) { //国家地区信息以0结束
// $data .= $char;
// $char = fread($this->fh, 1);
// }
// return $data;
// }
// //查询地区信息
// function getArea() {
// $byte = fread($this->fh, 1); //标志字节
// switch (ord($byte)) {
// case 0: $area = ''; break; //没有地区信息
// case 1: //地区被重定向
// fseek($this->fh, $this->getLong3());
// $area = $this->getInfo(); break;
// case 2: //地区被重定向
// fseek($this->fh, $this->getLong3());
// $area = $this->getInfo(); break;
// default: $area = $this->getInfo($byte); break; //地区没有被重定向
// }
// return $area;
// }
// function ip2addr($ip) {
// if(!$this -> checkIp($ip)){
// return false;
// }
// $ip = pack('N', intval(ip2long($ip)));
// //二分查找
// $l = 0;
// $r = $this->total;
// while($l <= $r) {
// $m = floor(($l + $r) / 2); //计算中间索引
// fseek($this->fh, $this->first + $m * 7);
// $beginip = strrev(fread($this->fh, 4)); //中间索引的开始IP地址
// fseek($this->fh, $this->getLong3());
// $endip = strrev(fread($this->fh, 4)); //中间索引的结束IP地址
// if ($ip < $beginip) { //用户的IP小于中间索引的开始IP地址时
// $r = $m - 1;
// } else {
// if ($ip > $endip) { //用户的IP大于中间索引的结束IP地址时
// $l = $m + 1;
// } else { //用户IP在中间索引的IP范围内时
// $findip = $this->first + $m * 7;
// break;
// }
// }
// }
// //查询国家地区信息
// fseek($this->fh, $findip);
// $location['beginip'] = long2ip($this->getLong4()); //用户IP所在范围的开始地址
// $offset = $this->getlong3();
// fseek($this->fh, $offset);
// $location['endip'] = long2ip($this->getLong4()); //用户IP所在范围的结束地址
// $byte = fread($this->fh, 1); //标志字节
// switch (ord($byte)) {
// case 1: //国家和区域信息都被重定向
// $countryOffset = $this->getLong3(); //重定向地址
// fseek($this->fh, $countryOffset);
// $byte = fread($this->fh, 1); //标志字节
// switch (ord($byte)) {
// case 2: //国家信息被二次重定向
// fseek($this->fh, $this->getLong3());
// $location['country'] = $this->getInfo();
// fseek($this->fh, $countryOffset + 4);
// $location['area'] = $this->getArea();
// break;
// default: //国家信息没有被二次重定向
// $location['country'] = $this->getInfo($byte);
// $location['area'] = $this->getArea();
// break;
// }
// break;
// case 2: //国家信息被重定向
// fseek($this->fh, $this->getLong3());
// $location['country'] = $this->getInfo();
// fseek($this->fh, $offset + 8);
// $location['area'] = $this->getArea();
// break;
// default: //国家信息没有被重定向
// $location['country'] = $this->getInfo($byte);
// $location['area'] = $this->getArea();
// break;
// }
// //gb2312 to utf-8(去除无信息时显示的CZ88.NET)
// foreach ($location as $k => $v) {
// $location[$k] = str_replace('CZ88.NET','',iconv('gb2312', 'utf-8', $v));
// }
// return $location;
// }
// //析构函数
// function __destruct() {
// fclose($this->fh);
// }
// }
class getIP {
public $proListIP = array("1.0","60.4","61.153","61.235","110.104","123.136","183.95","199.68","211.10","218.12","218.60","218.92","219.153","221.131","222.89","255.255");
//16组
function getLocation($NowIP){
$NowIPArray = explode('.', $NowIP);
if (count($NowIPArray) != 4){
return "IP格式出错";
}
$willCheckNumber = getIP::getCheckNumber($NowIP);
if (count($willCheckNumber) > 1){
for ($i = 0; $i < count($willCheckNumber); $i++) {
echo "$i:".$willCheckNumber[$i].'
';
}
}else{
echo $willCheckNumber;
}
//$NowIPArray[0]
return 0;
}
function getLocationFormMysql($NowIP){
}
function getCheckNumber($NowIP){
$NowIPArray = explode('.', $NowIP);
$MAXInt = 15;
for ($i = 0; $i < $MAXInt; $i++) {
$NowProListIPArray0 = explode('.', $this->proListIP[$i]);
$NowProListIPArray1 = explode('.', $this->proListIP[$i+1]);
if($NowIPArray[0] == $NowProListIPArray0[0]){
if($NowIPArray[1] == $NowProListIPArray0[1]){
if ($i == 0){
$willCheckNumber = $i;return $willCheckNumber;
}
$willCheckNumber = array($i,$i-1);return $willCheckNumber;
}else{
$willCheckNumber[] = $i;
}
if($NowIPArray[1] > $NowProListIPArray0[1] && $NowIPArray[1] < $NowProListIPArray1[1]){
$willCheckNumber = $i;return $willCheckNumber;
}
//IP第一位和I0第一位相等时,最后才写如果,IP第一位小于I1第一位。那么返回值
if($NowIPArray[0] < $NowProListIPArray1[0]){
$willCheckNumber = $i;return $willCheckNumber;
}
}
if($NowIPArray[0] == $NowProListIPArray1[0]){
if($NowIPArray[1] == $NowProListIPArray1[1]){
if ($i == 15){
$willCheckNumber = $i;return $willCheckNumber;
}
$willCheckNumber = array($i,$i+1);return $willCheckNumber;
}else{
$willCheckNumber[] = $i;
}
}
if($NowIPArray[0] > $NowProListIPArray0[0] && $NowIPArray[0] < $NowProListIPArray1[0]){
$willCheckNumber = $i;return $willCheckNumber;
}
}
}
function clientIP(){
$cIP = getenv('REMOTE_ADDR');
$cIP1 = getenv('HTTP_X_FORWARDED_FOR');
$cIP2 = getenv('HTTP_CLIENT_IP');
$cIP1 ? $cIP = $cIP1 : null;
$cIP2 ? $cIP = $cIP2 : null;
return $cIP;
}
function serverIP(){
return gethostbyname($_SERVER["SERVER_NAME"]);
}
}
function isInString($haystack, $needle) {
$haystack = '-_-!' . $haystack;
return (bool)strpos($haystack, $needle);
}
?>