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

php 获取当前用户的IP

WBOY
WBOY原創
2016-05-30 16:59:45809瀏覽

代码如下:

<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