function getip(){ if (isset($_server)) { if (isset($_server['http_x_forwarded_for'])) { $realip = $_server['http_x_forwarded_for']; } elseif (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); } elseif (getenv(http_client_ip)) { $realip = getenv(http_client_ip); } else { $realip = getenv(remote_addr); } } return $realip;}echo $ip = getip();
//新浪接口根据ip查询所在区域信息
$res0 = file_get_contents(http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip);$res0 = json_decode($res0,true);print_r($res0);echo
;
//淘宝接口根据ip查询所在区域信息
$res1 = file_get_contents(http://ip.taobao.com/service/getipinfo.php?ip=$ip);$res1 = json_decode($res1,true);print_r($res1);echo
;
以上就介绍了php获取ip地址以及ip地址所在位置,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
