How show IPv4 only with REMOTE_ADDR in PHP?

南楼画角 提交于 2019-12-20 01:41:44

问题


I have a question with variable : $_SERVER['REMOTE_ADDR']. I wish he recovers ONLY IP addresses in IPv4 format . It extracted me a few times in IPv6 format .

How to do?


回答1:


$_SERVER['REMOTE_ADDR'] always contains the address of the visitor. If it contains an IPv6 address then the visitor used IPv6 and there is no IPv4 address. And vice versa of course. These days you have to be able to deal with both.

Some visitors will have only IPv4, some will have only IPv6 and some will have both. The browser decides what is available and what it will use, and that's all you'll see. Note that a browser that has both might even switch between IPv4 and IPv6 between requests if it deems that necessary for good connectivity.



来源:https://stackoverflow.com/questions/31233216/how-show-ipv4-only-with-remote-addr-in-php

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