Test your IPv6 connectivity

Share
If you are connected to this blog using a IPv6 link, you will notice that near the top of the right column of the front page there is a message saying: "Congratulations ! You're using IPv6 ! Your address is XXXXXXX" In case you ask, the PHP code that performs this check is below:
if (substr_count($_SERVER['REMOTE_ADDR'],":") > 0 &&substr_count($_SERVER['REMOTE_ADDR'],".") == 0) {
echo 'Congratulations ! You're using IPv6 ! Your address is'.$_SERVER['REMOTE_ADDR'].'.';
}  else {
echo "You're just using IPv4. Your address is '.$_SERVER['REMOTE_ADDR'].'.';
}
Update: Martin J. Levy suggested the following, more compact code:
function is_connected_ipv6(){
return (substr_count($_SERVER['REMOTE_ADDR'], ":") > 0 && substr_count($_SERVER['REMOTE_ADDR'], ".") == 0);
}
echo is_connected_ipv6() ? "(via IPv6)" : "(via IPv4)";
Pages:
  1. What about this :

    echo strlen($_SERVER['REMOTE_ADDR']) > 15 ? 'IPv6' : 'IPv4';

    • Well, some IPv6 addresses, in compressed notation can theorically be shorter than 15 characters., the most obvious being “::1″. However, any IPv6 address will include at least on “:”.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>