/** * Validate the syntax of the given IPv4 adress. * * @param string IPv4 adress * @return boolean true if syntax is valid, otherwise false * @see IPv4::check() **/ public static function checkIP($ip) { return IPv4::check($ip); }
private function parseIP() { $ips = array(); $indices = array('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); foreach ($indices as $index) { $tip = @getenv($index); if (!empty($tip)) { $ips[] = $tip; } if (!empty($_SERVER[$index])) { $ips[] = $_SERVER[$index]; } } $ips = array_unique($ips); foreach ($ips as $key => $ip) { if (IPv4::check($ip)) { if (IPv4::checkPrivate($ip)) { return $ip; } } else { unset($ips[$key]); } } // Try a private one if (count($ips) > 0) { return end($ips); } else { // No ip found return null; } }