I want to check via php if someone connects to my site via IPv4 or IPv6.
The client address can be found in $_SERVER[\"REMOTE_ADDR\"]
but
Since the highest voted answer has a rather significant problem, I'm going to share my own.
This returns true if an address which appears to be IPv6 is passed in, and false if an address which appears to be IPv4 (or IPv4-mapped IPv6) is passed in. The actual addresses are not further validated; use filter_var()
if you need to validate them.
function is_ipv6($address) {
$ipv4_mapped_ipv6 = strpos($address, "::ffff:");
return (strpos($address, ":") !== FALSE) &&
($ipv4_mapped_ipv6 === FALSE || $ipv4_mapped_ipv6 != 0);
}