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

php 获取当前用户的IP

WBOY
WBOYOriginal
2016-05-30 16:59:45809browse

代码如下:

<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

Statement:
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