Home > Article > Backend Development > How to get visitor's ip address using php (code)
这篇文章给大家介绍的内容是关于如何使用php获取来访者的ip地址(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {//检查ip是从代{过}{滤}理传递过来的 $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip;
<?php echo "请求头IP". "<br/>Client_IP:".getenv('HTTP_CLIENT_IP'). "<br/>X_Forwarded_For(最右为真实IP):".getenv('HTTP_X_FORWARDED_FOR'). "<br/><hr>真实IP". "<br/>REMOTE_ADDR:".getenv('REMOTE_ADDR'). "<br/>\$_SERVER['REMOTE_ADDR']:".$_SERVER['REMOTE_ADDR'];
相关文章推荐:
如何用PHP将txt文件内容转换成数组并按行数获取指定内容(示例)
The above is the detailed content of How to get visitor's ip address using php (code). For more information, please follow other related articles on the PHP Chinese website!