Yesterday I was in need of detecting when a web site or page is accessed via either IPv6 or IPv4. I wrote two rather simplistic PHP functions that so far seem to be up to the job. They just look for an ocurrence of the symbol ":" in the "REMOTE_ADDR" server variable. Here they are:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
function is_ipv4($ip = "")
{
if (substr_count($ip,":") > 0 && substr_count($ip,".") == 0){
return false;
} else {
return true;
}
}
return is_ipv4($ip);
?>
|
<?php
$ip = $_SERVER['REMOTE_ADDR'];
function is_ipv6($ip = "")
{
if (substr_count($ip,":") > 0 && substr_count($ip,".") == 0){
return true;
} else {
return false;
}
}
return is_ipv6($ip);
?>
|
Both functions can be used in Drupal to hide / show a block when accesed via IPv6 or IPv4.