PHP write to get the search spider crawling record code

  • 2020-05-19 04:26:38
  • OfStack

So here is a piece of code written by php to get the crawling record of each search spider
Support for search engines as follows
Can record Baidu Google, Bing Yahoo, Soso, Sogou, Yodao crawl site record!
The php code is as follows
 
<?php 
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.ofstack.com.txt"; 
$time=nowtime(); 
$data=fopen($file,"a"); 
fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n"); 
fclose($data); 
} 
////www.ofstack.com collect  
?> 

Related articles: