Get visitors ipv4 behind cloudflare

倾然丶 夕夏残阳落幕 提交于 2020-01-06 02:27:11

问题


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'];
 }

回答1:


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

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".

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.




回答2:


Note that CF makes it's slightly more difficult to disable ipv6 (it's not possible from the gui, must be done by api) BUT they now include an option for to add a 'Pseudo IPv4' address to the headers - either by overwritting Cf-Connecting-IP and X-Forwarded-For or by adding a Cf-Pseudo-IPv4 header.

This can be quite handy as a stop-gap for legacy applications that don't (yet) support ipv6 - https://support.cloudflare.com/hc/en-us/articles/202494830-Pseudo-IPv4-Supporting-IPv6-addresses-in-legacy-IPv4-applications



来源:https://stackoverflow.com/questions/36294031/get-visitors-ipv4-behind-cloudflare

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!