如何在IPv4 PHP中处理IPv6地址 [英] How to handle IPv6 addresses alongside IPv4 PHP

查看:155
本文介绍了如何在IPv4 PHP中处理IPv6地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名iphone开发者 - 网络开发人员的新手,所以请耐心等待!
我目前正在使用MAMP进行本地测试。

I'm an iphone developer - new to web dev, so please be patient!
I'm currently using MAMP for local testing.

I在我的网站上有一个高度安全的部分。除了需要用户/通行证 - 它还会检查用户的IP。如果以前未使用该IP帐户,则会将该IP以及唯一ID添加到保留表中,并向用户发送一封电子邮件,要求确认从该位置访问其帐户。

I have a highly secure section on my site. Along with requiring a user/pass - it also checks the user's IP. If the account hasn't been used from that IP before, it will add that IP, along with a unique ID, to a holding table, and fire the user an email asking to confirm access them to their account from that location.

如果用户登录,并且他们的IP与我的允许表中与其用户ID关联的任何IP都不匹配,则执行上述任务,他们会收到电子邮件。

If the user logs in, and their IP doesn't match any IPs associated with their user ID in my 'allowed' table, it performs the above task, and they receive an email.

我用来生成他们点击的链接网址的代码看起来有点像这样:

The code I use to generate the url of the link they click on looks a bit like this:

if (preg_match('/^127./',$ip)) {
    // accessed from this machine
    $val_url = "http://localhost:8888/mywebsite/admin/aproove_ip.php?email=$admin_email&val=$hash";
}
else if (preg_match('/^192\.168./',$ip)) {
    // accessed form a local networked computer
    $val_url = "http://super.local:8888/mywebsite/admin/aproove_ip.php?email=$admin_email&val=$hash";
    // note super.local is my machine's address, 8888 is MAMP port
}
else {
    // accessed from the WWW
    $val_url = "http://www.mywebsite.com/admin/aproove_ip.php?email=$admin_email&val=$hash";
}

现在,在我的电脑上进行测试时,这非常有效。

Now, this has worked perfectly when testing on my computer.

但是,我决定(不要问为什么)从我的iPod Touch和它发给我的电子邮件(验证IP)进行测试,它给了我完整的在线地址如果它是从WWW访问的(即两个正则表达式都没有满足)。我查看了包含请求的保留表,请求的IP是: fe80 :: da30:62ff:fe18:6681

However, I decided (don't ask why) to test from my iPod Touch and in the email it sent me (to validate the IP), it gave me the full online address as if it had been accessed from the WWW (i.e. neither of the regexs were satisfied). I looked in the holding table which contains the requests, and the requested IP was: fe80::da30:62ff:fe18:6681.

我猜那是ipv6? - 我需要知道的是:

I'm guessing that's ipv6? - What I need to know is the following:


  • 我希望ipv6 addressess在我的网站上线时能够访问我的网站吗?

  • 我如何判断它是否是本地请求(如我的正则表达式为192.168 ......和127 ......)

我非常感谢任何有关这方面的建议,因为我发现它真的令人困惑

I would very much appreciate any advice on this as I find it really confusing

推荐答案

如果你想确保没有IPv6连接可以添加 收听0.0.0.0:80 到你的apache配置。但是大多数网络主机无论如何都不支持IPv6(我知道,我们是在2011年),所以人们甚至不太可能通过IPv6连接到你。你看到这个的唯一原因是因为bonjour(使 .local 地址工作的原因)在IPv6上运行。

If you want to ensure that no IPv6 connections happen can add Listen 0.0.0.0:80 to your apache configuration. But most web hosts don't support IPv6 yet anyway (ya I know, we're in 2011), so it's very unlikely that people can even connect to you via IPv6. The only reason your seeing this is because bonjour (what makes .local address work) runs over IPv6.

如果您希望将代码IPv6准备好,几乎不需要进行任何更改,因为大多数IP PHP功能都适用于IPv4和IPv6。我记得的唯一变化是将MySQL表中的varchar数据类型增加到IPv6地址的最大长度( 39 )。

If you want to get your code IPv6 ready, almost no changes need to be made as most IP PHP function work on both IPv4 and IPv6. The only change I remember making was increasing the varchar datatype in the MySQL table to the max length of a IPv6 address (39).

我不确定IPv6是否按照与IPv4相同的子网规则进行播放,但我希望验证IPv6地址是本地的要困难得多。

I'm not sure that IPv6 plays by the same rules of subnet that IPv4 does, but I expect it would be quite a bit harder to validate a IPv6 address is local.

编辑:

fe80 :: / 10 似乎是本地链接地址,可能就像检查前4位数一样简单。

fe80::/10 appears to be local link addresses, it might be as simple as checking the first 4 digits.

这篇关于如何在IPv4 PHP中处理IPv6地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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