简体   繁体   English

如何测试PHP应用程序的IPv6兼容性?

[英]How to test PHP application for IPv6 compatibility?

I have an existing php web application, I'm on IPv4, how can I fake IPv6 address to test the application compatibility with it? 我有一个现有的php web应用程序,我在IPv4上,我怎么能伪造IPv6地址来测试应用程序与它的兼容性? or is there a better way to test IPv6 compatibility? 或者有更好的方法来测试IPv6兼容性吗?

Update: My application log the ip of the user when he's making certain actions. 更新:我的应用程序在进行某些操作时记录用户的IP。 The IP addresses are stored in the database (from another question I can understand that BINARY is the best column type). IP地址存储在数据库中(从另一个问题我可以理解,BINARY是最好的列类型)。 The application should also be possible to search by IP. 应用程序也应该可以通过IP进行搜索。

I want apache / php to work as if I were using IPv6, I need to be sure my application compatibility with IPv6 is ready for production on both IPv4 networks + IPv6 networks. 我希望apache / php能像我使用IPv6一样工作,我需要确保我的应用程序与IPv6的兼容性已准备好在IPv4网络+ IPv6网络上进行生产。

I agree with Topener; 我同意Topener; don't worry about it, your website will run fine with IPv6. 不要担心,您的网站将与IPv6运行良好。 You don't need to worry about apache or PHP either, they will run fine. 您也不必担心apache或PHP,它们运行正常。

You should only care about storing IPv6 addresses in a database etc. Make sure you can store them in a proper way and that your database can handle an IPv6 address. 您应该只关心在数据库中存储IPv6地址等。确保您可以以正确的方式存储它们,并且您的数据库可以处理IPv6地址。

You can simply change $_SERVER['REMOTE_ADDR'] to an IPv6 address: 您只需将$ _SERVER ['REMOTE_ADDR']更改为IPv6地址即可:

echo $_SERVER['REMOTE_ADDR']; // will give you your current IP (probaply IPv4)

// change the REMOTE_ADDR to an IPv6 address
$_SERVER['REMOTE_ADDR'] = '3ffe:6a88:85a3:08d3:1319:8a2e:0370:7344';

You can find additional information about storing IPv6 addresses into a database here: 您可以在此处找到有关将IPv6地址存储到数据库的其他信息:

How to store IPv6-compatible address in a relational database 如何在关系数据库中存储与IPv6兼容的地址

Also note that for comparing IPv6 adresses, string comparison is not enough. 另请注意,为了比较IPv6地址,字符串比较是不够的。 There are different representations of the same IP adress, for example 2001:0DB8:0:0:1::1 is the short form of 2001:0db8:0000:0000:0001:0000:0000:0001 . 存在相同IP地址的不同表示,例如2001:0DB8:0:0:1::12001:0db8:0000:0000:0001:0000:0000:0001的缩写形式2001:0db8:0000:0000:0001:0000:0000:0001

Your website will run fine with IPv6. 您的网站将在IPv6中正常运行。 The only thing you need to test is, if you are storing IPv6, or logging of some kind, you should store it properly. 您需要测试的唯一事情是,如果您要存储IPv6,或者某种类型的日志记录,您应该正确存储它。 To fake this, just enter some variable and put it to the database, or whatever you want to do with it. 要伪造它,只需输入一些变量并将其放入数据库,或者您想用它做什么。

An example: 2001:db8::1:0:0:1 and 2001:0DB8:0:0:1::1 and fe80::202:b3ff:fe1e:8329 例如: 2001:db8::1:0:0:12001:0DB8:0:0:1::1fe80::202:b3ff:fe1e:8329

Otherwise, don't worry about it! 否则,不用担心!

If your application logs IP addresses then make sure that the fields to store them are big enough. 如果您的应用程序记录IP地址,请确保存储它们的字段足够大。 Make sure that any application that processes those logs knows how to deal with IPv6 addresses. 确保处理这些日志的任何应用程序都知道如何处理IPv6地址。 If you need to search for addresses by block/range you should use appropriate storage types for that. 如果您需要按块/范围搜索地址,则应使用适当的存储类型 If you do access control based on IP address then it becomes a bit more difficult because IPv6 clients might change their source address often when they have privacy extensions enabled, so you might want to allow access per /64 instead of per separate address. 如果您基于IP地址进行访问控制,则会变得有点困难,因为IPv6客户端可能会在启用了隐私扩展时经常更改其源地址,因此您可能希望允许每64位访问而不是每个单独的地址。

And most important: test, test, test :-) 最重要的是:测试,测试,测试:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM