如何使用php识别机器人?

2022-01-07 00:00:00 statistics bots php

我正在为我的用户建立统计数据,不希望计算机器人的访问量.

I am building stats for my users and dont wish the visits from bots to be counted.

现在我有一个基本的php,每次调用页面时mysql都会增加1.

Now I have a basic php with mysql increasing 1 each time the page is called.

但机器人也被添加到计数中.

But bots are also added to the count.

有人能想出办法吗?

主要是把事情搞砸的主要因素.谷歌、雅虎、MSN 等

Mainly is just the major ones that mess things up. Google, Yahoo, Msn, etc.

推荐答案

您应该按用户代理字符串进行过滤.您可以在此处找到机器人提供的大约 300 个常见用户代理的列表:http://www.robotstxt.org/db.html 在运行 SQL 语句之前运行该列表并忽略机器人用户代理应该可以解决所有实际目的的问题.

You should filter by user-agent strings. You can find a list of about 300 common user-agents given by bots here: http://www.robotstxt.org/db.html Running through that list and ignoring bot user-agents before you run your SQL statement should solve your problem for all practical purposes.

如果您甚至不希望搜索引擎访问该页面,请使用基本的robots.txt文件以阻止它们.

If you don't want the search engines to even reach the page, use a basic robots.txt file to block them.

相关文章