PHP判断访问者是否是搜索引擎机器人代码
function getrobot() {
if(!defined(‘IS_ROBOT’)) {
$kw_spiders = ‘Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla’;
$kw_browsers = ‘MSIE|Netscape|Opera|Konqueror|Mozilla’;
if(!strexists($_SERVER['HTTP_USER_AGENT'], ‘http://’) && preg_match("/($kw_browsers)/i", $_SERVER['HTTP_USER_AGENT'])) {
define(‘IS_ROBOT’, FALSE);
} elseif(preg_match("/($kw_spiders)/i", $_SERVER['HTTP_USER_AGENT'])) {
define(‘IS_ROBOT’, TRUE);
} else {
define(‘IS_ROBOT’, FALSE);
}
}
return IS_ROBOT;
}
Written by gegewan on 一月 10th, 2010 with
no comments.
Read more articles on 谈天说地.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article