1<?php
2require ("inet6.php");
3function valid_ipv6_address( $ipv6 )
4{
5    $regex = '/^(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|(25[0-5]|(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})\z/i';
6        if(!preg_match($regex, $ipv6))
7        return (false); // is not a valid IPv6 Address
8
9    return true;
10}
11
12/**
13    * Validate an IPv6 IP address
14	 *
15	 * @param  string $ip
16	 * @return boolean - true/false
17 */
18function isValidIPv6($ip)
19{
20   if ( false === filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) )
21  {
22       return false;
23	   }
24       return inet6_compress($ip);
25	}
26
27