I want to store the data returned by $_SERVER["REMOTE_ADDR"]
in PHP into a DB field, pretty simple task, really. The problem is that I can't find any proper information about the maximum length of the textual representation of an IPv6 address, which is what a webserver provides through $_SERVER["REMOTE_ADDR"]
.
I'm not interested in converting the textual representation into the 128 bits the address is usually encoded in, I just want to know how many characters maximum are needed to store any IPv6 address returned by $_SERVER["REMOTE_ADDR"]
.
:
characters. That is128 / 16 * 4 + 7
, which you can calculate usingdc(1)
on the command linedc -e "128 16 / 4 * 7 + p
, if installed. That will give you the maximum of 39 characters. Can be shorter as0
in beginning and in a range can be removed/reduced. That without counting the optional ending device name%devname
.