IPV6 notation of $_SERVER['REMOTE_ADDR']
ipv6, php
Solution
If you use `inet_pton()` first, and then convert it back to a string with `inet_ntop()` you should have a consistent string representation. I wouldn't rely on the input to be consistent...
Problem
I have many projects with functionalities relying on IP addresses provided by `$_SERVER['REMOTE_ADDR]`, `$_SERVER['HTTP_X_FORWARDED_FOR']`, and `$_SERVER['CLIENT_IP']`. IPV4 addresses are easy to match since we always receive them in the same format: 4 integers without the leading 0s, separated by a dot `.`. Whereas IPV6 addresses can be compressed. Ex: FF01:0:0:0:0:0:0:101 -> FF01::101 I've been researching this issue but haven't found anything relevant, so I'm asking for your experience. Is `$_SERVER['REMOTE_ADDR]` using a standard? Is it safe to assume that it will always be received as compressed or uncompressed? Or should I compress all my IPV6 string before I try to try test them? Note: Ideally I would like to handle IPV6 addresses as strings rather than binary structure, to improve readability in Databases / Source code and allow easier IP range matching.