0

I am trying to save an IPv6 address in a MySQL database. I am using inet_pton to do this. However, I have noticed that some IP's (in particular this localhost IP) are returning empty strings. Example:

$ip = inet_pton('::1'); 

And if a do a var_dump of $ip it shows that it's length is 16, but nothing is being returned:

var_dump($ip); // string(16) "" 

What is happening here?

0

1 Answer 1

4

IPv6 addresses are 128bit, which is 16 bytes/chars. ::1 corresponds to 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01, so you're printing 15 null bytes and 0x01, which is not a printable character.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.