将IPv6存储在数据库中 [英] Store IPv6 in database

查看:593
本文介绍了将IPv6存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL数据库中使用PHP存储IP的最佳做法是什么?
有一个名为ip2long的函数 - 但这仅适用于IPv4。
但是IPv6怎么样?

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?

我知道一个用于IPv6 IP的PHP函数,
但是它不适用于带有PHP<的Windows ;版本5.3

I know a php function that is for IPv6 IP's, but it doesn't work on Windows with PHP < Version 5.3

推荐答案

点分十进制IPv4地址可以转换为整数,最大大小为32位。 IPv6地址是128位。由于128位不适合PHP int,因此在PHP中使用会很麻烦。

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.

如果您只想连接并使用IPv6地址,请保存自己麻烦并将它们保存为文本。如果要应用网络掩码并计算子网,则需要转换它们。

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.

这篇关于将IPv6存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆