Send PHP spider statistics plugin as long as there is MySQL available _php tutorial

Source: Internet
Author: User
So yesterday then seriously did a bit, more functions, can be a variety of search engine statistical analysis. Can be viewed over a number of time periods. In fact the code is very simple, in order to be more concise, code compression to 6k. Divided into 6 files
1. Installation program spilder_install.php
Copy CodeThe code is as follows:




<title>Installing plugins</title>

if ($_post[' act ']== ' install ')//if it is installed
{
$mysql _host=trim ($_post[' mysql_host ');//Get Host
$mysql _user=trim ($_post[' mysql_user ');//Get User name
$mysql _pwd=trim ($_post[' mysql_pwd ');//Get password
$mysql _db=trim ($_post[' mysql_db ');//Database
$table _prefix=trim ($_post[' table_prefix ');//Get prefix
if ($link =mysql_connect ($mysql _host, $mysql _user, $mysql _pwd))
{
echo "Connect the server successfully! .................
";
}
Else
{
echo "";
}
if (mysql_select_db ($mysql _db, $link))
{
echo "Connect to the database successfully!" .............
Creating table ...... .......
";
}
$sql = "CREATE TABLE ' Spilder_sp_count ' (
' ID ' bigint (a) not NULL auto_increment,
' R_time ' int (one) is not NULL,
' r_name ' varchar (not NULL),
' R_url ' varchar ($) Not NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT charset=gb2312 auto_increment=4;
";
mysql_query ("DROP TABLE IF EXISTS '". $table _prefix. " Sp_count '; "); /delete already exists
$sql =str_replace ("Spilder_", $table _prefix, $sql);//Replace Prefix
if (mysql_query ($sql))
{
echo "Table created successfully! Writing file ";
}
$f =file_get_contents ("spilder_config.php");//Get Configuration content
$f =str_replace ("", "", $f);//Remove space
$f =preg_replace ("/mysql_host=.*;/ius", "mysql_host= ' {$mysql _host} ';", $f);
$f =preg_replace ("/mysql_user=.*;/ius", "mysql_user= ' {$mysql _user} ';", $f);
$f =preg_replace ("/mysql_pwd=.*;/ius", "mysql_pwd= ' {$mysql _pwd} ';", $f);
$f =preg_replace ("/mysql_db=.*;/ius", "mysql_db= ' {$mysql _db} ';", $f);
$f =preg_replace ("/table_prefix=.*;/ius", "table_prefix= ' {$table _prefix} ';", $f);
$f =preg_replace ("/sp_admin=.*;/ius", "sp_admin= ' {$sp _admin} ';", $f);
File_put_contents ("spilder_config.php", $f);
File_put_contents ("Isinstall.txt", "OK");
echo "Congratulations! Recommend the Spider Statistics Program installation successful view ";
Exit ();
}
?>





Recommended Spider Statistics Viewer





2. Spider record File
Copy CodeThe code is as follows:
Require ("spilder_config.php");//Invoke 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 Update time
$ServerName = $_server["SERVER_NAME"];
$ServerPort = $_server["Server_port"];
$ScriptName = $_server["Script_name"];
$QueryString = $_server["Query_string"];
$url = "http://". $ServerName;
If ($ServerPort! = "80")
{
$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
Copy CodeThe code is as follows:
Session_Start ();
Require ("spilder_config.php");
if ($_get[' act ']== ' logout ')
{
$_session[' ss_sp_admin ']= ';//Empty
}
if ($_get[' Sp_admin_login ')
{
if ($_get[' Sp_admin_login ']== $sp _admin)
{
$_session[' ss_sp_admin ']= $sp _admin;
}
}
Date_default_timezone_set (' PRC '); Set the default time zone
$day _start=strtotime (Date ("Ymd"). " 000001 ");//start Time of the day
$day _out=strtotime (Date ("Ymd"). " 235959 ");//The end time of the day
$day =3600*24;//Day Time
$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 ');//Connect 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)//delete 30 days ago
{
$d _time= $day _out-$day *30;
}elseif ($_get[' DT ']==2)//deleted 60 days ago
{
$d _time= $day _out-$day *60;
}elseif ($_get[' DT ']==3)//deleted 90 days ago
{
$d _time= $day _out-$day *90;
}elseif ($_get[' DT ']==4)//deleted 180 days ago
{
$d _time= $day _out-$day *180;
}elseif ($_get[' DT ']==5)//deleted 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 categorical statistics
{
if ($ss ==999)//Clear 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 classification statistics
if ($t ==0)//Constant condition
{
if (Empty ($_session[' ss_ss '))
{
$sql = "Select * FROM {$table _prefix}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;//of records per page
$pagecount =ceil ($rscount/$pagesize);//Get Total pages
$pageurl = "";
if ($page <=1)
{
$page = 1;
$pageurl. = "First Prev";
}else
{
$pageurl. = "First Prev";
}
if ($page >= $pagecount)
{
$page = $pagecount;
$pageurl. = "Next Page last";
}else
{
$pageurl. = "Next Page last";
}
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's Day stats
{
$s _time= $day _start;//start time
$e _time= $day _out;//End Time
$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 ==2)//view yesterday's 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_na Me ";
}elseif ($t ==3)//view statistics of the previous day
{
$s _time= $day _start-$day.
$e _time= $day _out-$day.
$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-day 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-day
{
$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-day 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_na Me ";
}
$res =mysql_query ($sql);/or Die ("Please install the program first");
?>



<title>Show Spider record Status</title>







Recommended Spider Viewer








Category View
All the
Baidu
Google
Bing
Yahoo
Sogou
Search
Youdao

Always
Today
Yesterday
Before
Seven days
30 days
90 days

if ($_session[' ss_sp_admin ']== $sp _admin)
{
?>





Management exit
Empty
30 days ago
60 days ago
90 days ago
180 days ago
360 days ago

}
?>
if ($t ==0)
{
?>
















while ($rs =mysql_fetch_array ($res)) {?> }?>
Spider Time Address
"target=" > "_blank"






}else{
?>














while ($rs =mysql_fetch_array ($res)) {?> }?>
Spider Statistics

}
?>




Links: Recommended gifts Love my parents hacker Empire



http://www.bkjia.com/PHPjc/322528.html www.bkjia.com true http://www.bkjia.com/PHPjc/322528.html techarticle so yesterday then seriously did a bit, more functions, can be a variety of search engine statistical analysis. Can be viewed over a number of time periods. In fact, the code is very simple, in order to be more concise, ...

  • 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.