$ _SERVER ['REMOTE_ADDR']的IPV6表示法 [英] IPV6 notation of $_SERVER['REMOTE_ADDR']
问题描述
我有许多项目的功能依赖于$_SERVER['REMOTE_ADDR]
,$_SERVER['HTTP_X_FORWARDED_FOR']
和$_SERVER['CLIENT_IP']
提供的IP地址.
I have many projects with functionalities relying on IP addresses provided by $_SERVER['REMOTE_ADDR]
, $_SERVER['HTTP_X_FORWARDED_FOR']
, and $_SERVER['CLIENT_IP']
.
IPV4地址很容易匹配,因为我们总是以相同的格式接收它们:4个整数,不带前导0,用点号.
分隔.
IPV4 addresses are easy to match since we always receive them in the same format: 4 integers without the leading 0s, separated by a dot .
.
而IPV6地址可以压缩.例如:FF01:0:0:0:0:0:0:101-> FF01 :: 101
Whereas IPV6 addresses can be compressed. Ex: FF01:0:0:0:0:0:0:101 -> FF01::101
我一直在研究此问题,但没有发现任何相关的内容,因此,我要求您提供经验. $_SERVER['REMOTE_ADDR]
是否使用标准?是否可以安全地假定它将始终以压缩或未压缩形式接收?
I've been researching this issue but haven't found anything relevant, so I'm asking for your experience. Is $_SERVER['REMOTE_ADDR]
using a standard? Is it safe to assume that it will always be received as compressed or uncompressed?
还是我应该先压缩所有IPV6字符串,然后再尝试对其进行测试?
Or should I compress all my IPV6 string before I try to try test them?
注意:
理想情况下,我想将IPV6地址作为字符串而不是二进制结构来处理,以提高数据库/源代码的可读性并允许更轻松的IP范围匹配.
Ideally I would like to handle IPV6 addresses as strings rather than binary structure, to improve readability in Databases / Source code and allow easier IP range matching.
推荐答案
如果使用 inet_pton()
,然后使用将其转换回字符串inet_ntop()
您应该具有一致的字符串表示形式.我不会依靠输入来保持一致...
If you use inet_pton()
first, and then convert it back to a string with inet_ntop()
you should have a consistent string representation. I wouldn't rely on the input to be consistent...
这篇关于$ _SERVER ['REMOTE_ADDR']的IPV6表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!