I read a few of the questions already asked, and i found this to be useful, although i have no tried it Working with IPv6 Addresses in PHP
Still, say i have a 'bans' table in MySQL. How would i go about storing the IPv6 address? The method must be universal, i.e the field must be able to contain either a ipv4 or ipv6 addr. This also must apply to my ip_addr field in my users table.
i would usually check if(getip == $bans['ip']) { do something }
But my getip function is for ipv4 afaik and i wonder if it will work.
The function i use is
function getip()
{
if(isset($_SERVER['REMOTE_ADDR']))
{
$ip = $_SERVER['REMOTE_ADDR'];
}
elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
if(preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s", $_SERVER['HTTP_X_FORWARDED_FOR'], $addresses))
{
foreach($addresses[0] as $key => $val)
{
if(!preg_match("#^(10|172\.16|192\.168)\.#", $val))
{
$ip = $val;
break;
}
}
}
}
if(!isset($ip))
{
if(isset($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
else
{
$ip = '';
}
}
$ip = preg_replace("#([^.0-9 ]*)#", "", $ip);
return $ip;
}