第一种修改好nginx或者Apache配置


第二种
HTTP_X_FORWARDED
/**
* 得到IP
* @return string
*/
public function getIP() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
} elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
} elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$this->ipPortToIp($ip);//得到IP
return $ip;
}
/**
* ip+port转成IP
* @param type $ip
* @return type
*/
public function ipPortToIp(&$ip) {
$array = explode(':', $ip);
if (count($array) > 1) {
$ip = $array[0];
}
return $ip;
}
                                关键字词:
                        
                        
                        
                    

 
                    