Store IPv6 in database

前端 未结 6 838
无人及你
无人及你 2020-12-08 22:12

What\'s the best practise to store IP\'s with PHP in MySQL database? There\'s a function called ip2long - but this is just for IPv4. But what about IPv6?

I know a ph

6条回答
  •  轮回少年
    2020-12-08 22:51

    The dotted-decimal IPv4 address can be converted to an integer, with a maximum size of 32 bits. IPv6 addresses are 128 bits. Since 128 bits do not fit in a PHP int, this will be a pain to work with in PHP.

    If you just want to connect and use IPv6 addresses, save yourself the trouble and save them as text. If you want to apply netmasks and calculate subnets, then you need to convert them.

提交回复
热议问题