Home  >  Article  >  Backend Development  >  Code written in PHP to obtain crawling records of each search spider_PHP tutorial

Code written in PHP to obtain crawling records of each search spider_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:17:36859browse

Then share below a code written in php to obtain the crawling records of various search spiders
Supports the following search engines
It can record the records of Baidu, Google, Bing, Yahoo, Soso, Sogou, Yodao crawling websites!
php The code is as follows:

Copy the code The code is as follows:

function get_naps_bot()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($useragent, 'googlebot') !== false){
return 'Google';
}
if (strpos($useragent, 'baiduspider') !== false){
return 'Baidu';
}
if (strpos($useragent, 'msnbot') !== false){
return 'Bing';
}
if (strpos($useragent, 'slurp') !== false){
return 'Yahoo';
}
if (strpos ($useragent, 'sosospider') !== false){
return 'Soso';
}
if (strpos($useragent, 'sogou spider') !== false){
return 'Sogou';
}
if (strpos($useragent, 'yodaobot') !== false){
return 'Yodao';
}
return false;
}
function nowtime(){
$date=date("Y-m-d.G:i:s");
return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
$url=$_SERVER['HTTP_REFERER'];
$file="www.jb51. net.txt";
$time=nowtime();
$data=fopen($file,"a");
fwrite($data,"Time:$time robot:$searchbot URL: $tlc_thispagen");
fclose($data);
}
//http://www.jb51.net collected and organized
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325712.htmlTechArticleThen let’s share a code written in php to obtain the crawling records of each search spider. The search engine can be recorded as follows: Baidu, Records of Google, Bing, Yahoo, Soso, Sogou, Yodao crawling websites! PHP code...
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