So yesterday I seriously did a bit more functions, can be a variety of search engine statistical analysis. Can be viewed in multiple time periods. In fact, the code is very simple, in order to more concise, code compression to 6k. Divided into 6 files
1. Setup spilder_install.php
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2. Spider record file
<?php require ("spilder_config.php")//Call configuration file $link =mysql_connect ($mysql _host, $mysql _user, $mysql _pwd) or Die ("
Server connection Error ")//Link Database mysql_select_db ($mysql _db, $link) or Die (' Database connection error ');
$searchbot = Get_naps_bot (); if ($searchbot) {date_default_timezone_set (' PRC ');//Set the default time zone $r _time=strtotime (date ("y-m-d h:i:s"))//Last updated $
ServerName = $_server["SERVER_NAME"];
$ServerPort = $_server["Server_port"];
$ScriptName = $_server["Script_name"];
$QueryString = $_server["Query_string"];
$url = "http://". $ServerName;
If ($ServerPort!= ")" {$url = $url. ":". $ServerPort;
$url = $url. $ScriptName; If ($QueryString!= "") {$url = $url. "?".
$QueryString;
}//$url = "http://". $_server[' http_host '].$_server[' Request_uri ']; $GLOBALS [' DB ']->db_query (insert into {$table _prefix}sp_count (R_time,r_name,r_url) VALUES (' $r _time ', ' $
Searchbot ', ' $url ') ");
function Get_naps_bot () {$useragent = Strtolower ($_server[' http_user_agent ')); if (Strpos ($useragent, ' Googlebot ')!== false) {
Return ' Googlebot ';
}elseif (Strpos ($useragent, ' MSNBot ')!== false) {return ' msnbot ';
}elseif (Strpos ($useragent, ' slurp ')!== false) {return ' Yahoobot ';
}elseif (Strpos ($useragent, ' Baiduspider ')!== false) {return ' Baiduspider ';
}elseif (Strpos ($useragent, ' Sogou ')!== false) {return ' Sogoubot ';
}elseif (Strpos ($useragent, ' Soso ')!== false) {return ' Sosobot ';
}elseif (Strpos ($useragent, ' Youdao ')!==false) {return ' Youdao ';
else {return false;
}}?>
3. Spider statistics View files
<?php session_start ();
Require ("spilder_config.php"); if ($_get[' act ']== ' logout ') {$_session[' ss_sp_admin ']= ';//Empty} if ($_get[' Sp_admin_login ']) {if ($_get[' Sp_admin_log ')
In ']== $sp _admin) {$_session[' ss_sp_admin ']= $sp _admin; } date_default_timezone_set (' PRC '); Sets the default time zone $day _start=strtotime (date ("Ymd"). 000001 ")//day start time $day _out=strtotime (" YMD ").
235959 ")//day end time $day =3600*24;//Day $link =mysql_connect ($mysql _host, $mysql _user, $mysql _pwd) or Die (" Server connection error "); mysql_select_db ($mysql _db, $link) or Die (' Link database error ');//Connection database if ($_get[' act ']== ' del ') {if ($_session[' ss_sp_admin ']
<> ') {if ($_get[' DT ']==0)//Empty {mysql_query ("delete from {$table _prefix}sp_count");
} $d _time=0;
if ($_get[' DT ']==1)//deleted 30 days ago {$d _time= $day _out-$day *30;
}elseif ($_get[' DT ']==2)/delete 60 days ago {$d _time= $day _out-$day *60;
}elseif ($_get[' DT ']==3)/delete 90 days ago {$d _time= $day _out-$day *90;
}elseif ($_get[' DT ']==4)/delete 180 days ago {$d _time= $day _out-$day *180; }elseif ($_get[' DT ']==5)//Delete 360 days ago {$d _time= $day _out-$day *360; } if ($d _time>0) {mysql_query ("delete from {$table _prefix}sp_count where r_time< ' $d _time '");//Delete Data}}} $SS =
Intval ($_get[' SS ']);
if ($ss >0)//View the category statistics {if ($ss ==999)//empty category {$_session[' ss_ss ']= ';
}else {$_session[' ss_ss ']= $ss;
}} $ss =$_session[' Ss_ss '];
if ($ss ==1) {$ss = ' baiduspider ';
}elseif ($ss ==2) {$ss = ' Googlebot ';
}elseif ($ss ==3) {$ss = "msnbot";
}elseif ($ss ==4) {$ss = "Yahoobot";
}elseif ($ss ==5) {$ss = "Sogoubot";
}elseif ($ss ==6) {$ss = "Sosobot";
}elseif ($ss ==7) {$ss = 7; } $t =intval ($_get[' t '])//view time sorting statistics if ($t ==0)/times ({if (Empty ($_session[' ss_ss '))) {$sql = "select * FROM {$table _p
Refix}sp_count ORDER BY id DESC "//Latest situation $sql 2=" SELECT COUNT (*) from {$table _prefix}sp_count ";
}else {$sql = "select * FROM {$table _prefix}sp_count where r_name= ' $SS ' ORDER by id DESC";
$sql 2= "SELECT COUNT (*) from {$table _prefix}sp_count where r_name= ' $ss '";
$rscount =mysql_query ($sql 2); $rscount = @mysqL_fetch_array ($rscount); $rscount = $rscount [0];//Gets the total number of records $page =intval (Trim ($_get[' page '));/Current page $pagesize =30;//the number of records per page $pagecount =ceil ($
rscount/$pagesize);//Get the total number of pages $pageurl = "";
if ($page <=1) {$page = 1;
$pageurl. = "First Prev"; }else {$pageurl. = "<a href= '? page=1&ss=". $ss. "' > Home </a> <a href= '? ss= '. $ss. " &page= ". ($page-1). "'
> Prev </a> ";
} if ($page >= $pagecount) {$page = $pagecount;
$pageurl. = "Next page last"; }else {$pageurl. = "<a href= '? ss=". $ss. " &page= ". ($page + 1). "' > Next </a> <a href= '? ss= '. $ss. " &page= ". $pagecount." '
> Last </a> ";
} if ($page <=1) {$page = 1; $start _rs=intval (($page-1) * $pagesize);//Start $end _rs=intval ($page * $pagesize);//end $sql. = "Limit {$start _rs},{$end _
RS} "; } if ($t ==1)//view today Day statistics {$s _time= $day _start;//start time $e _time= $day _out;//end Time $sql = "SELECT count (*) as Ct,r_name from {$ta
Ble_prefix}sp_count where r_time between ' $s _time ' and ' $e _time ' GROUP by R_name '; }elseif ($t ==2)//view yesterday statistics {$s _time= $day _start-$day;/start $e _time= $day _out-$day;/End $sql = "SELECT count (*) as Ct,r_name from {$table _
Prefix}sp_count where r_time between ' $s _time ' and ' $e _time ' GROUP by R_name ';
}elseif ($t ==3)//view before the daily statistics {$s _time= $day _start-$day *2;
$e _time= $day _out-$day *2; $sql = "SELECT count (*) as Ct,r_name from {$table _prefix}sp_count where r_time between ' $s _time ' and ' $e _time ' GROUP by R_na
Me ";
}elseif ($t ==4)//view seven days of statistics {$s _time= $day _start-$day *7;
$e _time= $day _out; $sql = "SELECT count (*) as Ct,r_name from {$table _prefix}sp_count where r_time between ' $s _time ' and ' $e _time ' GROUP by R_na
Me ";
ElseIf ($t ==5)//view 30 days {$s _time= $day _start-$day *30;
$e _time= $day _out; $sql = "SELECT count (*) as Ct,r_name from {$table _prefix}sp_count where r_time between ' $s _time ' and ' $e _time ' GROUP by R_na
Me ";
}elseif ($t ==6)//View 90 days of statistics {$s _time= $day _start-$day *90;
$e _time= $day _out; $sql = "SELECT count (*) as Ct,r_name from {$table _prefix}sp_count where r_time between ' $s _time ' and' $e _time ' GROUP by R_name ';
$res =mysql_query ($sql);//or Die ("Please install program <a href= ' spilder_install.php ' > Install </a>"); ? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">