validate_ip($ip) || $this->validate_ipv6($ip)) && $ip !== $serverIp) { return $ip; } } } } return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false; } /** * Ensures an ip address is both a valid IP and does not fall within * a private network range. */ function validate_ipv6($ip) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { return true; } return false; } function validate_ip($ip) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) { return false; } return true; } } }