1,首先获取IP地址
2,通过淘宝接口获取当前为止
============第一部分===========
function getIP()
{
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")){
$realip = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;
}
=============第二部分============
function getAddr($ip = '')
{
// 获取得到一个数组country(国家),area(地区),region(省),city(城市),isp(网络运营商),ip(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=json_decode(file_get_contents($url));
if((string)$ip->code=='1'){
return false;
}
$data = (array)$ip->data;
}
return $data;
}