首页 > 代码库 > php 获取客户端ip

php 获取客户端ip

 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