Home > php教程 > php手册 > php获取当前ip

php获取当前ip

WBOY
Release: 2016-06-07 11:42:53
Original
1321 people have browsed it

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元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template