Record each search spider crawl log PHP code

Source: Internet
Author: User
Tags date log php code return

Records of Baidu,google,bing,yahoo,soso,sogou,yodao crawl sites can be recorded

The code is as follows:

01 <?php
02 Http://www.tongqiong.com
03 function Get_naps_bot ()
04 {
05 $useragent = Strtolower ($_server[' http_user_agent '));
06
07 if (Strpos ($useragent, ' Googlebot ')!== false) {
08 Return ' Google ';
09 }
10
11 if (Strpos ($useragent, ' Baiduspider ')!== false) {
12 Return ' Baidu ';
13 }
14 if (Strpos ($useragent, ' MSNBot ')!== false) {
15 Return ' Bing ';
16 }
17
18 if (Strpos ($useragent, ' slurp ')!== false) {
19 Return to ' Yahoo ';
20 }
21st
22 if (Strpos ($useragent, ' Sosospider ')!== false) {
23 Return ' Soso ';
24 }
25
26 if (Strpos ($useragent, ' Sogou spider ')!== false) {
27 Return ' Sogou ';
28 }
29
30 if (Strpos ($useragent, ' Yodaobot ')!== false) {
31 Return ' Yodao ';
32 }
33 return false;
34 }
35
36 function Nowtime () {
37 $date =date ("y-m-d.g:i:s");
38 return $date;
39 }
40
41 $searchbot = Get_naps_bot ();
42
43 if ($searchbot) {
44 $TLC _thispage = addslashes ($_server[' http_user_agent '));
45 $url =$_server[' Http_referer '];
46 $file = "Www.tongqiong.com.txt";
47 $time =nowtime ();
48 $data =fopen ($file, "a");
49 Fwrite ($data, "Time: $time Robot: $searchbot URL: $TLC _thispage\n");
50 Fclose ($data);
51 }
52 Http://www.tongqiong.com
53 ?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.