php获取用户 地区 、ip地址

header("Content-type: text/html; charset=utf-8"); 

function getCity($ip = '')//获取地区
{
if($ip == ''){
$url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json";//新浪借口获取访问者地区
$ip=json_decode(file_get_contents($url),true);
$data = $ip;
}else{
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;//淘宝借口需要填写ip
$ip=json_decode(file_get_contents($url));
if((string)$ip->code=='1'){
return false;
}
$data = (array)$ip->data;
} return $data;
} print_r($city); //获取访问者ip地址 if ($_SERVER['REMOTE_ADDR']) {//判断SERVER里面有没有ip,因为用户访问的时候会自动给你网这里面存入一个ip
$cip = $_SERVER['REMOTE_ADDR'];
} elseif (getenv("REMOTE_ADDR")) {//如果没有去系统变量里面取一次 getenv()取系统变量的方法名字
$cip = getenv("REMOTE_ADDR");
} elseif (getenv("HTTP_CLIENT_IP")) {//如果还没有在去系统变量里取下客户端的ip
$cip = getenv("HTTP_CLIENT_IP");
} else {
$cip = "unknown";
}
echo $cip;

  

上一篇:直接双击运行PowerShell的脚本文件


下一篇:转载blog_Linux下Tomcat日志定期清理 及 logrotate 配置