Try the following function, it will convert a IPv4 address to IPv6 /** * Convert an IPv4 address to IPv6 * * @param string IP Address in dot notation (192.168.1.100) * @return string IPv6 formatted address or false if invalid input */ function IPv4To6($Ip) { static $Mask = '::ffff:'; // This tells IPv6 it has an IPv4 address $IPv6 = (strpos($Ip, '::') === 0); $IPv4 = (strpos($Ip, '.') > 0); if (!$IPv4 && !$IPv6) return false; if ($IPv6 && $IPv4) $Ip = substr($Ip, strrpos($Ip, ':')+1); // Strip IPv4 Compatibility notation elseif (!$IPv4) return $Ip; // Seems to be IPv6 already? $Ip = array_pad(explode('.', $Ip), 4, 0); if (count($Ip) > 4) return false; for ($i = 0; $i < 4; $i++) if ($Ip[$i] > 255) return false; $Part7 = base_convert(($Ip[0] * 256) + $Ip[1], 10, 16); $Part8 = base_convert(($Ip[2] * 256) + $Ip[3], 10, 16); return $Mask.$Part7.':'.$Part8; } PHP:
the same way as ipv4 using $_SERVER['REMOTE_ADDR'] if that variable contains ipv4 address it means that client doesnt have ipv6, your server has missconfigured ipv6, your webserver doesnt have ipv6 support, your domain doesnt have aaaa record or if your site got both ipv4 and ipv6 address and everything is configured properly then most likely clients primary routing is via ipv4 (which is unusual but also might happen - might be forced by client or clients isp).
i have test my server have support ipv6 using IPv6test -f /proc/net/if_inet6 && echo "Running kernel is IPv6 ready" to test my server , actually , i want to get user ipv4 and ipv6 when user have visit my site , is it possible ? anyone can give me more example ?
but do u have ipv6 addresses assigned to your server? if not you should get /64 or /48 from some ipv6 tunnel broker (google: "ipv6 tunnel"; tunnelbroker.net is the easiest way). Each tunnel broker will provide you with additional software or instructions how to enable your newly assigned ipv6 addresses to your server. once u get ipv6 addresses up and running (test with "ping6 someipv6hostname" command), you need to assign it to your domain (add AAAA record for your domain, the same way u add A record for ipv4) last step is to bind your webserver to ipv6 address (most likely you will find example how to do it in your webserver config file, it is also possible that your webserver already binds on all available interfaces so u dont need to change anything).