Hi there,
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 how to check if it's IPv4 or IPv6 ?
Thank you for your time
Andre
Hi there,
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 how to check if it's IPv4 or IPv6 ?
Thank you for your time
Andre
What about counting the number of '.'
and/or ':
' in $_SERVER["REMOTE_ADDR"]
?
If there is more than 0 ':
', and no '.
' symbol in $_SERVER["REMOTE_ADDR"]
, I suppose you can consider you user is connected via IPv6.
Another solution might be to use the filter extension : there are constants (see the end of the page) that seem to be related to IPv4 and IPv6 :
FILTER_FLAG_IPV4
(integer)
Allow only IPv4 address in "validate_ip" filter.
FILTER_FLAG_IPV6
(integer)
Allow only IPv6 address in "validate_ip" filter.
You can use this:
function ipVersion($txt) {
return strpos($txt, ":") === false ? 4 : 6;
}