在哪里阅读访客信息 [英] Where to read the visitor info

查看:61
本文介绍了在哪里阅读访客信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

此问题暴露了 visitor count 的过时,最糟糕的方法,因此所有人都应避免使用此方法.使用复杂的计数器.

This question exposed the obsolete, worst approach for visitors count and it should be avoided by everyone out there. Use sophisticated counters.

推荐答案

由于找不到令人满意的足够简单"的解决方案,因此我提出了自己的解决方案.创建一个名为 ip.txt 的空文件,并在代码中的某个位置使用该文件:

Since I didn't find a satisfying "simple enough" solution, I came up with my own. Create an empty file called ip.txt and use this somewhere in your code:

$ip_all = file("ip.txt");
$ip_cur = $_SERVER['REMOTE_ADDR']."\n";
if (!in_array($ip_cur, $ip_all)) {
    $ip_all[] = $ip_cur;
    file_put_contents("ip.txt", implode($ip_all));
}

echo "visitors: " . count($ip_all);

请注意,此文件会随着时间的流逝而变大,具体取决于您获得的访问者数量,因为条目不会过期并且会像Cookie一样被删除.但是,正如已经提到的,我希望它尽可能简单,并且不在乎.另外,我也不想依靠cookie,因为我怀疑网络爬虫和其他机器人会将它们发送回去.

Note that this file will can get somewhat large over time depending on the amount of visitors you get since the entries don't expire and get deleted like cookies. But as already mentioned, I wanted it to be as simple as possible and don't care about that. Also I don't want to rely on cookies because I doubt web-crawlers and other robots will send them back.

这篇关于在哪里阅读访客信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆