Store IPV6 and IPV4 in MySql, and also read them

I have a php site. I want to save the last ip for each user. I want it to work for both IPV4 and IPV6 users. Any idea how?

+4
source share
1 answer

Just convert them to binary using inet_pton(), and then go back to the line using inet_ntop().

Another solution would be to save the IP string without any conversion to the database. Field VARCHAR(39)will complete the task as the highest / longest IPv6ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff

+6
source

All Articles