A quick search on Google lead me here: http://stackoverflow.com/questions/12435...shows-ipv6
Yet, also note this: http://stackoverflow.com/questions/31233...ddr-in-php
Quote:The server is then accepting connections on an IPv6 socket. Some operating systems can do both IPv4 and IPv6 on an IPv6 socket. When that happens the IPv6 address will look like
orCode:::ffff:192.0.2.123
which is the same address but written in hexadecimal.Code:::ffff:c000:027b
If you see IPv6 addresses like
then your webserver really is reachable over IPv6 :-)Code:2a00:8640:1::224:36ff:feef:1d89
Anyway, to convert everything back to a canonical form you can use something like:
Using this code, when you input one of the following:Code:// Known prefix
$v4mapped_prefix_hex = '00000000000000000000ffff';
$v4mapped_prefix_bin = pack("H*", $v4mapped_prefix_hex);
// Or more readable when using PHP >= 5.4
# $v4mapped_prefix_bin = hex2bin($v4mapped_prefix_hex);
// Parse
$addr = $_SERVER['REMOTE_ADDR'];
$addr_bin = inet_pton($addr);
if( $addr_bin === FALSE ) {
// Unparsable? How did they connect?!?
die('Invalid IP address');
}
// Check prefix
if( substr($addr_bin, 0, strlen($v4mapped_prefix_bin)) == $v4mapped_prefix_bin) {
// Strip prefix
$addr_bin = substr($addr_bin, strlen($v4mapped_prefix_bin));
}
// Convert back to printable address in canonical form
$addr = inet_ntop($addr_bin);
you always get the canonical IPv4 addressCode:::ffff:192.000.002.123
::ffff:192.0.2.123
0000:0000:0000:0000:0000:ffff:c000:027b
::ffff:c000:027b
::ffff:c000:27b
192.000.002.123
192.0.2.123
as output.Code:192.0.2.123
And of course IPv6 addresses get returned as canonical IPv6 addresses:
becomesCode:2a00:8640:0001:0000:0224:36ff:feef:1d89
etc.Code:2a00:8640:1::224:36ff:feef:1d89
Yet, also note this: http://stackoverflow.com/questions/31233...ddr-in-php
Quote:always contains the address of the visitor. If it contains an IPv6 address then the visitor used IPv6 and there is no IPv4 address. And vice versa of course. These days you have to be able to deal with both.Code:$_SERVER['REMOTE_ADDR']
Some visitors will have only IPv4, some will have only IPv6 and some will have both. The browser decides what is available and what it will use, and that's all you'll see. Note that a browser that has both might even switch between IPv4 and IPv6 between requests if it deems that necessary for good connectivity.