我正在尝试使用 PHP 的 $_SERVER['REMOTE_ADDR'] 来跟踪和记录访问我的网站的用户/访问者.PHP中IP地址跟踪的典型方法.
I'm trying to track and log users/visitors that are accessing my website using PHP's $_SERVER['REMOTE_ADDR'] to do so. A typical method for IP address tracking in PHP.
但是,我使用 CloudFlare 进行缓存等,并以 CloudFlare 的形式接收它们的 IP 地址:
However, I am using CloudFlare for caching and such and receiving their IP addresses as CloudFlare's:
108.162.212.* - 108.162.239.*
108.162.212.* - 108.162.239.*
在仍然使用 CloudFlare 的同时检索实际用户/访问者 IP 地址的正确方法是什么?
What would be a correct method of retrieving the actual users/visitors IP address while still using CloudFlare?
可用于 Cloudflare 的额外服务器变量有:
Extra server variables that are available to cloud flare are:
$_SERVER["HTTP_CF_CONNECTING_IP"] 真实访问者ip地址,这就是你想要的
$_SERVER["HTTP_CF_CONNECTING_IP"] real visitor ip address, this is what you want
$_SERVER["HTTP_CF_IPCOUNTRY"] 访问者所在国家
$_SERVER["HTTP_CF_RAY"]
$_SERVER["HTTP_CF_VISITOR"] 这可以帮助你知道它是 http 还是 https
$_SERVER["HTTP_CF_VISITOR"] this can help you know if its http or https
你可以这样使用它:
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
如果您这样做,并且访问 IP 地址的有效性很重要,您可能需要验证 $_SERVER["REMOTE_ADDR"] 是否包含实际有效的 cloudflare IP 地址,因为任何人如果他能够直接连接到服务器 IP,则可以伪造标头.
If you do this, and the validity of the visiting IP address is important, you might need to verify that the $_SERVER["REMOTE_ADDR"] contains an actual valid cloudflare IP address, because anyone can fake the header if he was able to connect directly to the server IP.
这篇关于CloudFlare 并通过 PHP 记录访问者 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)