首页 >php教程 >php手册 >php 获取当前用户的IP

php 获取当前用户的IP

WBOY
WBOY原创
2016-05-30 16:59:45815浏览

代码如下:

<span style="color: #000000;">php
   </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_CLIENT_IP'<span style="color: #000000;">]){
     </span><span style="color: #800080;">$onlineip</span>=<span style="color: #800080;">$_SERVER</span>['HTTP_CLIENT_IP'<span style="color: #000000;">];
}</span><span style="color: #0000ff;">elseif</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_X_FORWARDED_FOR'<span style="color: #000000;">]){
     </span><span style="color: #800080;">$onlineip</span>=<span style="color: #800080;">$_SERVER</span>['HTTP_X_FORWARDED_FOR'<span style="color: #000000;">];
}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
     </span><span style="color: #800080;">$onlineip</span>=<span style="color: #800080;">$_SERVER</span>['REMOTE_ADDR'<span style="color: #000000;">];
}
</span><span style="color: #008000;">/*</span><span style="color: #008000;"> 何问起 hovertree.com </span><span style="color: #008000;">*/</span>

<span style="color: #0000ff;">echo</span> <span style="color: #800080;">$onlineip</span><span style="color: #000000;">;

</span>?>

推荐:http://www.cnblogs.com/roucheng/p/phpexcel.html

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