Detecting IPv6 addresses

Can someone please comment if the following code will be suitable for detecting if I am dealing with an IPv6 address? I am worried about this because I know very little about IPv6 and have never knowingly encountered one.

$ip = $_SERVER['REMOTE_ADDR'];

if (strlen($ip) >= 16)
{
	// found IPv6 address
}

I want the code in the if statement to execute if $ip yields an ipv6 addresses. Normal v4 IPS max out at 15 characters, I believe. (255.255.255.255)

Sorry to burst your bubble…but IPv6 is capable of being much smaller then IPv4 for example:

127.0.0.1 <---> ::1

The simplist method for detecting IPv6 is to look for colons “:” Or use PHP’s filter functions. http://us.php.net/manual/en/filter.filters.flags.php

[TABLE=“class: doctable table, width: 0”]
[TR]
[TD=“bgcolor: #F0F0F0, align: left”]FILTER_FLAG_IPV4[/TD]
[TD=“bgcolor: #F0F0F0, align: left”]FILTER_VALIDATE_IP[/TD]
[TD=“bgcolor: #F0F0F0, align: left”]Allows the IP address to be in IPv4 format.[/TD]
[/TR]
[TR]
[TD=“bgcolor: #F0F0F0, align: left”]FILTER_FLAG_IPV6[/TD]
[TD=“bgcolor: #F0F0F0, align: left”]FILTER_VALIDATE_IP[/TD]
[TD=“bgcolor: #F0F0F0, align: left”]Allows the IP address to be in IPv6 format.[/TD]
[/TR]
[/TABLE]

Well I’m glad I asked!

So the following would work for detecting IPv6s?

if (strpos($ip, ':') == true)
{
 // IPv6 found
}

or

if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == true)
{
   // IPv6 found
}

I can’t test these because I do not know how to actually use an IPv6 address, so I don’t know if it these code snippets would actually work.