public static function checkIPv6($ip) { $ipPart = SimplePie_Net_IPv6::SplitV64($ip); $count = 0; if (!empty($ipPart[0])) { $ipv6 = explode(':', $ipPart[0]); for ($i = 0; $i < count($ipv6); $i++) { $dec = hexdec($ipv6[$i]); $hex = strtoupper(preg_replace('/^[0]{1,3}(.*[0-9a-fA-F])$/', '\\1', $ipv6[$i])); if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex === strtoupper(dechex($dec))) { $count++; } } if ($count === 8) { return true; } elseif ($count === 6 && !empty($ipPart[1])) { $ipv4 = explode('.', $ipPart[1]); $count = 0; foreach ($ipv4 as $ipv4_part) { if ($ipv4_part >= 0 && $ipv4_part <= 255 && preg_match('/^\\d{1,3}$/', $ipv4_part)) { $count++; } } if ($count === 4) { return true; } } else { return false; } } else { return false; } }