How to recognize bots with php?(如何使用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.
这篇关于如何使用php识别机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用php识别机器人?
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
