获取cloudflare背后的访客ipv4 [英] Get visitors ipv4 behind cloudflare

查看:140
本文介绍了获取cloudflare背后的访客ipv4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想获得访客IP地址。一切都很好,但是一个用户只给了我IPv6。
这是我可以给您的代码,此外,我刚刚安装了cloudflare apache2 Mod。

I just have the problem that I want to get the visitors IP Address. Everythings fine but one user just give me the IPv6. This is the code I can give you, moreover I just had installed the cloudflare apache2 Mod.

 $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"] ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"];
 $ip = $_SERVER['REMOTE_ADDR'];

 if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
     $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
 }


推荐答案

唯一的方法将通过以下方式禁用CloudFlare中的IPv6支持:

The only way to do this would be to disable IPv6 support in CloudFlare by:

1)在DNS中删除所有AAAA记录(仅保留A记录)。
2)在CloudFlare仪表板上进入网络并关闭 IPv6兼容性。

1) In DNS removing all AAAA records (leaving only A records). 2) Going into the Network on the CloudFlare dashboard and turning off "IPv6 Compatibility".

我不建议这样做;您可能很快就会遇到无法连接到您网站的人。相反,最好是确保您的平台完全支持IPv6。

I would not recommend this though; you might soon find yourself with people unable to connect to your site. Instead it is a better idea to make sure your platform fully supports IPv6.

这篇关于获取cloudflare背后的访客ipv4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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