Home > Backend Development > PHP Tutorial > 啥是机器人!该如何解决

啥是机器人!该如何解决

WBOY
Release: 2016-06-13 12:10:34
Original
1123 people have browsed it

啥是机器人!

本帖最后由 discuz2015 于 2014-11-27 15:29:48 编辑
define('ISROBOT', getrobot());<br />if(defined('NOROBOT') && ISROBOT) {<br />	exit(header("HTTP/1.1 403 Forbidden"));<br />}<br />
Copy after login

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

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

------解决思路----------------------
Bot
------解决思路----------------------
Crawl
------解决思路----------------------
Spider
------解决思路----------------------
slurp
------解决思路----------------------
sohu-search
------解决思路----------------------
lycos
------解决思路----------------------
robozilla
是正则要匹配的模式
Bot,Spider...都是蜘蛛的标识,一般的搜索引擎都会写
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template