php获取当前ip<?php <br />
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];<br>
$user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];<br>
$URL='http://ip.taobao.com/service/getIpInfo.php?ip='.$user_IP;<br>
$fcontents = file_get_contents("$URL");<br>
$contents=json_decode($fcontents);<br>
?><br>
<br>
<br>
<meta>
<br>
<title>pr查询</title>
<br>
<br>
<br>
<br>
<?php <br />
echo '您来自: '.$contents->data->country.$contents->data->area.$contents->data->region.$contents->data->city.' ip为'.$contents->data->ip;<br>
?><br>
<br>
<br>
另外在附一份tp自带的吧:
参考:https://github.com/liu21st/thinkphp/blob/master/ThinkPHP/Library/Org/Net/IpLocation.class.php/*<br>
* 根据ip地址获取所在城市<br>
*/<br>
protected function checkUserArea(){<br>
import("ORG.Net.IpLocation");<br>
$myip=get_client_ip();<br>
$Ip=new IpLocation("UTFWry.dat");//导入ip库 参考http://thinkphp.cn/extend/270.html 把下载的文件放在Lib\ORG\Net下<br>
$area=$Ip->getlocation($myip);<br>
return $area;<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元