I need to convert IPv6 addresses to IPv4 addresses. To do this, I used code from pedmillon's answer to a related question:
$ipv6 = $_SERVER['REMOTE_ADDR'];
$ipv4 = hexdec(substr($ipv6, 0, 2)). "." . hexdec(substr($ipv6, 2, 2)). "." . hexdec(substr($ipv6, 5, 2)). "." . hexdec(substr($ipv6, 7, 2));
I tried it in my localhost and ::1 gets converted to 0.1.0.0. Is this code correctly working?
I believe it should be showing 127.0.0.1 instead of 0.1.0.0.