Post 

Software

PHP snipplet for detecting users with IPv6

Should I ever need to detect with PHP if a user has IPv6, this code snipplet should do the job:

<?php
$ip = getenv ("REMOTE_ADDR");
if (substr_count($ip,":") > 0
    && substr_count($ip,".") == 0) {
 echo 'You are using <a '
  .'href="http://www.dnsstuff.com/tools/whois.ch?ip='
  . $ip . '"> IPv6 </a>';
} else {
  echo "You are using IPv4";
}
?>

Leave a comment

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by Movable Type 5.02