I have IP database for a certain country. I have paid version of Ip2Lcoation and i got all the IPv6 ranges and IPv4. In my web app I am converting all the IPs to long using ip2long function.
It works perfectly with IPv4 but with IPv6 it fails? i searched and found few functions which didn't work. My Code is as follows
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$long = ip2long($ip);// fails at IPv6
//mysql query to check the ip ranges
$cri= new CDbCriteria();
$cri->condition="$long>=ip_range_start AND $long<=ip_range_end";
if (UsaIps::model()->exists($cri))
{
return true;
}
else
{
return false;
}
How can i achieve this ??
Any guide any help??