简体   繁体   English

PHP 上的客户端 IPv6 但节点服务器上的 IPv4 - 需要它们相同

[英]Client IPv6 on PHP but IPv4 on node server - need them to be same

I am running into an issue in relation to security and verification.我遇到了与安全和验证有关的问题。 I have a software that checks to confirm a user, and I need to make sure it's the same client sending a PHP request and a node server request.我有一个软件可以检查以确认用户,我需要确保发送 PHP 请求和节点服务器请求的是同一个客户端。 However, on the node server, the client's IP is shown in IPv4, and on the PHP it is shown in IPv6.但是,在节点服务器上,客户端的 IP 显示为 IPv4,而在 PHP 上显示为 IPv6。 Is there any way I can get the same output somewhere, for example extract the IPv6 on the node server, or the IPv4 on the PHP server?有什么办法可以在某处获得相同的 output,例如在节点服务器上提取 IPv6,或者在 PHP 服务器上提取 IPv4? Thanks.谢谢。

Obtaining the same IP or verifying that it is the same client despite a "different" IPv4 and IPv6获取相同的 IP 或验证它是同一个客户端,尽管有“不同”的 IPv4 和 IPv6

The problem is that IPv6 and IPv4 are not coupled in any way.问题是 IPv6 和 IPv4 没有以任何方式耦合。 There's no way to deduce a v6 address from the v4 address or the other way around.无法从 v4 地址或其他方式推断出 v6 地址。

In my humble opionion, verifying users by their IP addresses is something you should avoid as IP addresses are spoofable , and the practice leads to these kind of issues.在我看来,你应该避免通过 IP 地址验证用户,因为 IP 地址是可欺骗的,这种做法会导致这类问题。 That said, there are a couple of "solutions".也就是说,有几个“解决方案”。

  • Disable IPv6 on the webserver that's hosting the PHP application.在托管 PHP 应用程序的网络服务器上禁用 IPv6。 Since you haven't mentioned which type of webserver this is, you should be able to google something like 'disable ipv6 apache' on how to achieve this.由于您没有提到这是哪种类型的网络服务器,您应该能够通过谷歌搜索“禁用 ipv6 apache”之类的内容来了解如何实现这一点。 This should garantuee an identical IPv4 address on both servers.这应该保证两台服务器上的 IPv4 地址相同。 I personally don't particularly like this solution as it hinders IPv6 adoption.我个人不是特别喜欢这个解决方案,因为它阻碍了 IPv6 的采用。

  • Enable IPv6 on the node server .节点服务器上启用 IPv6。 Please note that clients can still prefer IPv4 over IPv6 for any reason at all and there's no way to garantuee that it will use IPv6 to both webservers.请注意,客户端仍然可以出于任何原因更喜欢 IPv4 而不是 IPv6,并且无法保证它将对两个 Web 服务器都使用 IPv6。

  • You could proxy all calls from one webserver to the other and pass the original IP in for example an 'X-Forwarded-For' header. This will introduce some overhead, but the source IP will be stabler.您可以将所有调用从一个网络服务器代理到另一个,并将原始 IP 传递到例如“X-Forwarded-For”header 中。这会引入一些开销,但源 IP 会更稳定。

  • Personally, I'd shy away from using the IP address and implement some sort of token stored on the client that can be verified on both servers by means of a shared database if that is an option.就个人而言,我会回避使用 IP 地址并实现某种存储在客户端上的令牌,如果可以的话,可以通过共享数据库在两台服务器上进行验证。

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

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