20,359
社区成员
发帖
与我相关
我的任务
分享
$r = taobaoIP('119.75.217.109');
print_r($r);
/**
* 根据ip获得信息
* @param [type] $clientIP [ip]
* @return [type] [description]
*/
function taobaoIP($clientIP){
$taobaoIP = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$clientIP;
$IPinfo = json_decode(file_get_contents($taobaoIP),true);
$data = $IPinfo['data'];
return $data;
}
Array
(
[country] => 中国
[country_id] => CN
[area] => 华北
[area_id] => 100000
[region] => 北京市
[region_id] => 110000
[city] => 北京市
[city_id] => 110100
[county] =>
[county_id] => -1
[isp] => 百度网络
[isp_id] => 100099
[ip] => 119.75.217.109
)
function getip() {
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$cip = $_SERVER["HTTP_CLIENT_IP"];
} else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (!empty($_SERVER["REMOTE_ADDR"])) {
$cip = $_SERVER["REMOTE_ADDR"];
} else {
$cip = "";
}
return $cip;
}
function taobaoIP($clientIP){
$taobaoIP = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$clientIP;
$IPinfo = json_decode(file_get_contents($taobaoIP),true);
$data = $IPinfo['data'];
return $data;
}
$data = taobaoIP(getip());
if(isset($data['region']) && $data['region']=='北京市'){
header('location:http://beijing.com'); // 北京ip
}else{
header('location:http://other.com'); // 其他ip
}