首页 >php教程 >php手册 >php获取当前ip

php获取当前ip

WBOY
WBOY原创
2016-06-07 11:42:531316浏览

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元

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn