protected static function detectAndCleanIP()
{
$ip = self::detectIP();
if (strstr($ip, ',') !== false || strstr($ip, ' ') !== false) {
$ip = str_replace(' ', ',', $ip);
$ip = str_replace(',,', ',', $ip);
$ips = explode(',', $ip);
$ip = '';
while (empty($ip) && !empty($ips)) {
$ip = array_pop($ips);
$ip = trim($ip);
}
} else {
$ip = trim($ip);
}
return $ip;
}