// 获取IP地址
function GetIP() {
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$thisip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$thisip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$thisip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$thisip = $_SERVER['REMOTE_ADDR'];
}
preg_match("/[\d\.]{7,15}/", $thisip, $thisips);
$thisip = $thisips[0] ? $thisips[0] : 'unknown';
return $thisip;
}
已经测试过了。可以获取到真实的IP地址!TCP/IPv4
可以直接放代码里用就行了 。不用谢。请叫我‘雷锋’