如何阻止Bot在PHP脚本上运行某些代码? [英] How to stop bots from running some code on PHP script?

查看:105
本文介绍了如何阻止Bot在PHP脚本上运行某些代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本将在每次查看页面时添加到数据库中,我不希望机器人触发脚本部分添加到数据库中.基本上,我只想记录真实用户.

I have a script which will add to a databse everytime a page is viewed, I don't want bots triggering the script portion which adds to the database. Basically, I want to only log real users.

是否总是让漫游器忽略一部分PHP脚本?

Anyway to have bots ignore a section of PHP script?

谢谢!

推荐答案

虽然不是万无一失的,但是您可以检查USER_AGENT字符串,并且仅在'bot'不存在的情况下才运行该代码.

While not foolproof, you can check the USER_AGENT string and only run that code if 'bot' does not exist.

if(stripos($_SERVER['HTTP_USER_AGENT'],'bot') === false){ }

这将停止在用户代理字符串中实际包含bot的所有bot,这些bot也不关注robots.txt.

This would stop any bot that actually has bot in the user agent string that also does not pay attention to robots.txt.

这篇关于如何阻止Bot在PHP脚本上运行某些代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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