问题描述
我在做一个计数器。我有一个数据库,我存储的IP地址和 $ _ SERVER ['HTTP_USER_AGENT'];参观者
。现在,我需要添加一个过滤器,这样我就可以收起命中,由机器人进行。我发现,很多僵尸通常会保留一些常用词语的 $ _ SERVER ['HTTP_USER_AGENT'];
,所以我的喜欢做和文字的排列,这将保持机器人从结果中显示。
I'm making a hit counter. I have a database and I store the IP and $_SERVER['HTTP_USER_AGENT'];
of the visitors. Now I need to add a filter, so I can put away the hits, that are made by bots. I found out, that many bots usually keep some common words in the $_SERVER['HTTP_USER_AGENT'];
, so I's like to make and array of words, that would keep the bot from displaying in the results.
这是我现在有:
while($row = mysql_fetch_array($yesterday, MYSQL_ASSOC)) {
< - 在这里,我需要一个code,这将通过阵列上运行,检查,
如果containts的关键字,如果它不...算了算++; - >
<-- Here I need a code, that would run through an array and check,if it containts the keywords and if it doesn't ... just count++; -->
}
另外,如果你知道的检测和删除的结果机器人任何其他方式,我很感激柠。干杯
Also if you know any other way of detecting and removing the bots from the results, I'd be verry thankful. Cheers
推荐答案
遍历字的阵列的foreach
,并检查是否使用了UA字符串存在当前字:
Loop through the array of words with foreach
and check if the current word exists in the UA string using strpos():
foreach ($words as $word) {
if (strpos($row['user_agent'], $word) !== FALSE) {
// word exists in string
}
}
这篇关于PHP / MySQL的 - 对于机器人的数组过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!