What is the correct way to save an IP in the database?

0

How to save both types of IP the IPV4 and IPV6 in a MySQL database? What is the correct typing and column size? Any other comments?

I get the IP through $_SERVER['REMOTE_ADDR'] with PHP.

    
asked by anonymous 25.10.2017 / 17:05

1 answer

0

There are functions to use in IPV4.

For IPv4 addresses, you may want to store them as a int unsigned and use the INET_ATON() and INET_NTOA() functions to return the IP address of your numeric value and vice versa.

link

link

For IPv6:

Use this type VARBINARY(16)

link

    
25.10.2017 / 17:30