天天看點

php 判斷是否是機器人,如何用PHP檢測搜尋引擎機器人?

檢查下面$_SERVER['HTTP_USER_AGENT']列出的一些字元串:

或者更具體地說是爬蟲:

如果您想 - 記錄大多數常見搜尋引擎抓取工具的通路次數,您可以使用$interestingCrawlers = array( 'google', 'yahoo' );$pattern = '/(' . implode('|', $interestingCrawlers) .')/';$matches = array();$numMatches = preg_match($pattern, strtolower($_SERVER['HTTP_USER_AGENT']), $matches, 'i');if($numMatches > 0) // Found a match{

// $matches[1] contains an array of all text matches to either 'google' or 'yahoo'}