function getIp() {
if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
elseif( isset($_SERVER['HTTP_CLIENTIP']) ) {
$ip = $_SERVER['HTTP_CLIENTIP'];
}
elseif( isset($_SERVER['REMOTE_ADDR']) ) {
$ip = $_SERVER['REMOTE_ADDR'];
}
elseif( getenv('HTTP_X_FORWARDED_FOR') ) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif( getenv('HTTP_CLIENTIP') ) {
$ip = getenv('HTTP_CLIENTIP');
}
elseif( getenv('REMOTE_ADDR') ) {
$ip = getenv('REMOTE_ADDR');
}
else {
$ip = '127.0.0.1';
}
$pos = strpos($ip, ',');
if( $pos > 0 ) {
$ip = substr($ip, 0, $pos);
}
return trim($ip);
}