PHP判断城市ip
更新时间:2023-02-20 08:59 已阅读: 次 | 作者:骏马网络 来源:潍坊做网站PHP实现IP自动判断城市效能
<?php
function GetIP() {
if ($_SERVER["HTTP_X_FORWARDED_FOR"])
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if ($_SERVER["HTTP_CLIENT_IP"])
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if ($_SERVER["REMOTE_ADDR"])
$ip = $_SERVER["REMOTE_ADDR"];
else if (getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "Unknown";
return $ip;
}
$ip=GetIP();
$bb='123.53.228.184';
$json=file_get_contents('http://ip.taobao.com/outGetIpInfo?ip='.$ip.'&accessKey=alibaba-inc');
$arr=json_decode($json);
$city= $arr->data->region; //省份
echo $arr->data->country; //国家
echo $arr->data->area; //区域
echo $arr->data->region; //省份
echo $arr->data->city; //城市
echo $arr->data->isp; //运营商
//echo $city;
if ($city=='山东'){
echo "<SCRIPT LANGUAGE='javascript'>";
echo "location.href='/404.html'";
echo "</SCRIPT>";
exit();
die;
}
if ($city=='山东'){
echo "<SCRIPT LANGUAGE='javascript'>";
echo "location.href='/404.html'";
echo "</SCRIPT>";
exit();
die;
}
文章引用:https://www.wfwz.net/seo/257.html如需转载,请注明出处。