Home  >  Article  >  Backend Development  >  啥是机器人!

啥是机器人!

WBOY
WBOYOriginal
2016-06-23 13:44:20871browse

define('ISROBOT', getrobot());if(defined('NOROBOT') && ISROBOT) {	exit(header("HTTP/1.1 403 Forbidden"));}

上面这段代码,据说是防止机器人访问的,我不理解哪里代表是机人呢

判断机器人的函数是这么写的,这里面有啥玄机吗
function getrobot() {	if(!defined('IS_ROBOT')) {		$kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';		$kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';		if(preg_match("/($kw_browsers)/", $_SERVER['HTTP_USER_AGENT'])) {			define('IS_ROBOT', FALSE);		} elseif(preg_match("/($kw_spiders)/", $_SERVER['HTTP_USER_AGENT'])) {			define('IS_ROBOT', TRUE);		} else {			define('IS_ROBOT', FALSE);		}	}	return IS_ROBOT;}


回复讨论(解决方案)

Bot-微软的bing
Spider-百度
slurp-雅虎
其他几个不知道,不过这也只能防止正常的抓取,人家伪造了也不一定能防止

Bot-微软的bing
Spider-百度
slurp-雅虎
其他几个不知道,不过这也只能防止正常的抓取,人家伪造了也不一定能防止


难道就没有一个好办办吗

流氓要抓也没办法,不过一般的搜索引擎都遵循robots协议

流氓要抓也没办法,不过一般的搜索引擎都遵循robots协议


$kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';是啥意思呢

Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla
是正则要匹配的模式
Bot,Spider...都是蜘蛛的标识,一般的搜索引擎都会写

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn