php 获取客户端ip

时间:2014-04-30 01:42:33   收藏:0   阅读:422
bubuko.com,布布扣
 1 function getRealIp() {
 2         if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
 3            $ip = getenv("HTTP_CLIENT_IP");
 4         else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
 5            $ip = getenv("HTTP_X_FORWARDED_FOR");
 6         else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
 7            $ip = getenv("REMOTE_ADDR");
 8         else if (isset($_SERVER[‘REMOTE_ADDR‘]) && $_SERVER[‘REMOTE_ADDR‘] && strcasecmp($_SERVER[‘REMOTE_ADDR‘], "unknown"))
 9            $ip = $_SERVER[‘REMOTE_ADDR‘];
10         else
11            $ip = "unknown";
12         return($ip);
13     }
View Code

 

php 获取客户端ip,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!