sekedar berbagi PHP code yang saya buat untuk mendeteksi source IPv6 beserta IPv6 enable logo, silahkan dimodifikasi sesuai dengan kebutuhan masing masing, mudah-mudahan bisa bermanfaat;
<div id=ipv6_enabled_www_test_logo></div>
<script language="JavaScript" type="text/javascript">
var Ipv6_Js_Server = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + Ipv6_Js_Server + "www.ipv6forum.com/ipv6_enabled/sa/SA1.php?id=771' type='text/javascript'%3E%3C/script%3E"));
</script>
<?php
class ipv6
{
function is_ipv6($ip = "")
{
if ($ip == "")
{
$ip = ipv6::get_ip();
}
if (substr_count($ip,":") > 0 && substr_count($ip,".") == 0){
return true;
} else {
return false;
}
}
/*
* Detect if an IP is IPv4
*
* @param ip adresse ip . tester
* @return true / false
*/
function is_ipv4($ip = "")
{
return !ipv6::is_ipv6($ip);
}
/*
* return user IP
*
* @return IP
*/
function get_ip()
{
return getenv ("REMOTE_ADDR");
}
/*
* Uncompress an IPv6 address
*
* @param ip adresse IP IPv6 . d.compresser
* @return ip adresse IP IPv6 d.compress.
*/
function uncompress_ipv6($ip ="")
{
if ($ip == "")
{
$ip = ipv6::get_ip();
}
if(strstr($ip,"::" ))
{
$e = explode(":", $ip);
$s = 8-sizeof($e)+1;
foreach($e as $key=>$val)
{
if ($val == "")
{
for($i==0;$i<=$s;$i++)
$newip[] = 0;
} else {
$newip[] = $val;
}
}
$ip = implode(":", $newip);
}
return $ip;
}
/*
* Compress an IPv6 address
*
* @param ip adresse IP IPv6 . compresser
* @return ip adresse IP IPv6 compress.
*/
function compress_ipv6($ip ="")
{
if ($ip == "")
{
$ip = ipv6::get_ip();
}
if(!strstr($ip,"::" ))
{
$e = explode(":", $ip);
$zeros = array(0);
$result = array_intersect ($e, $zeros );
if (sizeof($result) >= 6)
{
if ($e[0]==0) {$newip[] = "";}
foreach($e as $key=>$val)
{
if ($val !=="0")
{
$newip[] = $val;
}
}
$ip = implode("::", $newip);
}
}
return $ip;
}
}
/*
* IPv6 Compression
*/
/*
* IPv6 Uncompression
*/
echo "IPv6 ENABLE || " ;
/*
* Tester IPv6
*/
echo "Your IP is ".ipv6::get_ip()." And You're using : ";
echo (ipv6::is_ipv6())? "IPv6":"IPv4";
echo "<br>";
?>