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

不言
Release: 2023-04-03 16:28:02
Original
2023 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
Client_IP:".getenv('HTTP_CLIENT_IP'). "
X_Forwarded_For(最右为真实IP):".getenv('HTTP_X_FORWARDED_FOR'). "

真实IP". "
REMOTE_ADDR:".getenv('REMOTE_ADDR'). "
\$_SERVER['REMOTE_ADDR']:".$_SERVER['REMOTE_ADDR'];
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!