How to get visitor's ip address using php (code)

不言
Release: 2023-04-03 16:28:02
Original
2121 people have browsed it

这篇文章给大家介绍的内容是关于如何使用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;
Copy after login
<?php
echo
"请求头IP".
"<br/>Client_IP:".getenv(&#39;HTTP_CLIENT_IP&#39;).
"<br/>X_Forwarded_For(最右为真实IP):".getenv(&#39;HTTP_X_FORWARDED_FOR&#39;).
"<br/><hr>真实IP".
"<br/>REMOTE_ADDR:".getenv(&#39;REMOTE_ADDR&#39;).
"<br/>\$_SERVER[&#39;REMOTE_ADDR&#39;]:".$_SERVER[&#39;REMOTE_ADDR&#39;];
Copy after login

相关文章推荐:

如何用PHP读取excel文件内容、获取单元格数据

php中对字符串的各种判断小结

如何用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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template