Detect IPv6 in PHP?

I am currently discovering an IPv4 user address and using IP blocks with v4. However, I want to capture IPv6 and have block lists for this too, so the question is: Is this the same logic as IPv6, like IPv4 or something else in PHP? I'm just not sure that each device has IPv4 and IPv6, or is it either one of them, and the system will automatically determine which format it stores?

+6
php ip-address ipv6
source share
1 answer

Apache reports REMOTE_ADDR PHP. If Apache is listening on the v6 interface, it will be the address of v6.

Easy to differentiate. IPv4 addresses will always have a fullstop character . , and IPv6 addresses will always contain a colon :

When creating blocklists (or whitelists), you should be careful with v6 addresses. They can be shortened using two consecutive colons :: . There is no guarantee that your OS will use a shorter or longer form, so your script should handle this. See the Wikipedia IPv6 page for more details.

+6
source share

All Articles