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)";
Recent Comments