Home>Article>Backend Development> How to get visitor's ip address using php (code)

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

不言
不言 Original
2018-08-06 14:36:52 2049browse

这篇文章给大家介绍的内容是关于如何使用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;
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'];

相关文章推荐:

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

Statement:
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