protected static function getIpVersion($ip)
    {
        // Test for IPv4
        if (ip2long($ip) !== false)
        {
            return "IPv4";
        }
         
        // Test for IPv6
        if (substr_count($ip, ":" ) < 2) return false; // ::1 or 2001::0db8
        if (substr_count($ip, "::") > 1) return false; // one allowed
        
        $groups = explode(':', $ip);
        $num_groups = count($groups);
        if (($num_groups > 8) || ($num_groups < 3)) return false;

        $empty_groups = 0;
        foreach ($groups as $group)
        {
            $group = trim($group);
            if (!empty($group) && !(is_numeric($group) && ($group == 0)))
            {
                if (!preg_match('#([a-fA-F0-9]{0,4})#', $group)) return false;
            }
            else
            {
                ++$empty_groups;
            }
        }
		if ($empty_groups < $num_groups)
		{
			return "IPv6";
		}
		return false; // no (valid) IP Address
	}
protected static function getIpVersion($ip)
    {
        // Test for IPv4
        if (ip2long($ip) !== false)
        {
            return "IPv4";
        }
         
        // Test for IPv6
        if (substr_count($ip, ":" ) < 2) return false; // ::1 or 2001::0db8
        if (substr_count($ip, "::") > 1) return false; // one allowed
        
        $groups = explode(':', $ip);
        $num_groups = count($groups);
        if (($num_groups > 8) || ($num_groups < 3)) return false;

        $empty_groups = 0;
        foreach ($groups as $group)
        {
            $group = trim($group);
            if (!empty($group) && !(is_numeric($group) && ($group == 0)))
            {
                if (!preg_match('#([a-fA-F0-9]{0,4})#', $group)) return false;
            }
            else
            {
                ++$empty_groups;
            }
        }
		if ($empty_groups < $num_groups)
		{
			return "IPv6";
		}
		return false; // no (valid) IP Address
	}
protected static function getIpVersion ( $ ip ) { // Test for IPv4 if ( ip2long ( $ ip ) !== false ) { return "IPv4" ; } // Test for IPv6 if ( substr_count ( $ ip , ":" ) < 2 ) return false ; // ::1 or 2001::0db8 if ( substr_count ( $ ip , "::" ) > 1 ) return false ; // one allowed $ groups = explode ( ':' , $ ip ) ; $ num_groups = count ( $ groups ) ; if ( ( $ num_groups > 8 ) || ( $ num_groups < 3 ) ) return false ; $ empty_groups = 0 ; foreach ( $ groups as $ group ) { $ group = trim ( $ group ) ; if ( ! empty ( $ group ) && ! ( is_numeric ( $ group ) && ( $ group == 0 ) ) ) { if ( ! preg_match ( '#([a-fA-F0-9]{0,4})#' , $ group ) ) return false ; } else { ++ $ empty_groups ; } } if ( $ empty_groups < $ num_groups ) { return "IPv6" ; } return false ; // no (valid) IP Address }
Helperfunction, IP =  IPv4 or IPv6 ?

@param string $ip	IP Address (IPv4 or IPv6)
@return mixed		false: no valid IPv4 and no valid IPv6
"IPv4" : IPv4 Address
"IPv6" : IPv6 Address
@access public
Helperfunction IP = IPv4 or IPv6 ?