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

Source: Internet
Author: User
Tags echo date prev
So yesterday I seriously did a bit more function, 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. Installation program spilder_install.php
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Installing Plug-ins </title>
<?php
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! .................<br> ";
}
Else
{
echo "<script>alert (' link Error! Please check the database server configuration! '); History.go ( -1);</script> ";
}
if (mysql_select_db ($mysql _db, $link))
{
echo "Connect the database successfully!" .............<br> is creating table ................<br> ";
}
$sql = "CREATE TABLE ' Spilder_sp_count ' (
' ID ' bigint 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 to File ";
}
$f =file_get_contents ("spilder_config.php");//Get Configuration content
$f =str_replace ("", "", $f);//Remove spaces
$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! Recommended Spider statistics program installed successfully <a href=\ "Index.php\" > View </a>;
Exit ();
}
?>
<body>
<table width= "border=" "0" align= "center" >
<tr>
&LT;TD align= "center" > Recommended Spider Statistics Viewer </td>
</tr>
</table>
<form method= "POST" >
<table width= "border=" "0" align= "center" cellspacing= "0" >
<tr>
&LT;TD width= "280" > </td>
&LT;TD width= "610" > Start installation </td>
</tr>
<tr>
&LT;TD align= "Right" > Server:</td>
<td><input name= "Mysql_host" type= "text" id= "mysql_host" value= "localhost"/>
(generally do not change) </td>
</tr>
<tr>
&LT;TD align= "Right" > Username:</td>
<td><input type= "text" name= "Mysql_user" id= "Mysql_user"/></td>
</tr>
<tr>
&LT;TD align= "Right" > Password:</td>
<td><input type= "Password" name= "mysql_pwd" id= "Mysql_pwd"/></td>
</tr>
<tr>
&LT;TD align= "Right" > Database:</td>
<td><input type= "text" name= "mysql_db" id= "mysql_db"/></td>
</tr>
<tr>
&LT;TD align= "right" > table prefix:</td>
<td><input name= "Table_prefix" type= "text" id= "Table_prefix" value= "Spilder_"/>
<input name= "Act" type= "hidden" id= "Act" value= "install"/></td>
</tr>
<tr>
&LT;TD align= "Right" > Admin password:</td>
<td><input type= "Password" name= "Sp_admin" id= "Sp_admin"/></td>
</tr>
<tr>
&LT;TD align= "right" > </td>
<td><input type= "Submit" name= "button" id= "button" value= "Install"/></td>
</tr>
</table>
</form>
</body>

2. Spider record File
Copy Code code as follows:

<?php
Require ("spilder_config.php");//Calling configuration file
$link =mysql_connect ($mysql _host, $mysql _user, $mysql _pwd) or Die ("Server connection Error");//Linked 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 Code code as follows:

<?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_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 ");//day's start time
$day _out=strtotime (Date ("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 ');//Connect database
if ($_get[' act ']== ' del ')
{
if ($_session[' ss_sp_admin ']<> ')
{
if ($_get[' DT ']==0)/clear
{
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 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 classification statistics
if ($t ==0)//AT all times
{
if (Empty ($_session[' ss_ss '))
{
$sql = "Select * FROM {$table _prefix}sp_count order by id DESC";/update
$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
Number of records per page $pagesize =30;//
$pagecount =ceil ($rscount/$pagesize);//Get Total 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 {$table _prefix}sp_count where r_time between ' $s _time ' and ' $e _time ' GROUP by R_na Me ";
}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_na Me ";
}elseif ($t ==3)//view every day before the 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_na Me ";
}
$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 ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> display Spider record situation </title>
<style type= "Text/css" >
td{font-size:14px;}
A,a:link{text-decoration:none color: #000;}
A:hover{color: #F00;}
</style>
<body>
<table width= "border=" "0" align= "center" cellspacing= "1" bgcolor= "#CCCCCC" style= "margin-bottom:6px"; >
<tr>
&LT;TD height= "align=" center "bgcolor=" #66CC00 "></tr>
</table>
<table width= "border=" "0" align= "center" cellspacing= "1" bgcolor= "#CCCCCC" >
<tr>
&LT;TD width= "height=" bgcolor= "#FFFFFF" > Category View </td>
&LT;TD width= "403" align= "center" bgcolor= "#FFFFFF" >
<a href= "? ss=999" > All </a>
<a href= "? Ss=1" > Baidu </a>
<a href= "? ss=2" > Google </a>
<a href= "? ss=3" > Bing </a>
<a href= "? ss=4" > Yahoo </a>
<a href= "? ss=5" > Sogou </a>
<a href= "ss=6" > Search </a>
<a href= "? ss=7" > Youdao </a></td>
&LT;TD width= "322" bgcolor= "#FFFFFF" >
<a href= "t=0" > Always </a>
<a href= "? t=1" > Today </a>
<a href= "? t=2" > Yesterday </a>
<a href= "? t=3" > The day before yesterday </a>
<a href= "? t=4" > Seven days </a>
<a href= "? t=4" >30 Day </a>
<a href= "? t=5" >90 Day </a>
</td>
</tr>
</table>
<?php
if ($_session[' ss_sp_admin ']== $sp _admin)
{
?>
<table width= "border=" 0 "align=" center "cellspacing=" 1 "bgcolor=" #CCCCCC "style=" MARGIN-TOP:12PX; margin-bottom:12px; " >
<tr>
&LT;TD width= "align=" "Right" bgcolor= "#FFFFFF" > Management <a href= "? act=logout" > Exit </a> </td>
&LT;TD width= "585" align= "center" bgcolor= "#FFFFFF" >
<a href= "? act=del&dt=0" onclick= "return confirm (' OK Empty ')" > Empty </a>
<a href= "? act=del&dt=1" onclick= "return confirm (' OK delete? ') ' >30 days ago </a>
<a href= "? act=del&dt=2" onclick= "return confirm (' OK delete? ') ' >60 days ago </a>
<a href= "? act=del&dt=3" onclick= "return confirm (' OK delete? ') ' >90 days ago </a>
<a href= "? act=del&dt=4" onclick= "return confirm (' OK delete? ') ' >180 days ago </a>
<a href= "? act=del&dt=5" onclick= "return confirm (' OK delete? ') ' >360 days ago </a></td>
</tr>
</table>
<?php
}
?>
<?php
if ($t ==0)
{
?>
<table width= "border=" "0" align= "center" cellspacing= "1" bgcolor= "#CCCCCC" style= "margin-top:6px"; >
<tr>
&LT;TD width= "align=" "Center" bgcolor= "#FFFFFF" > Spider </td>
&LT;TD width= "217" align= "center" bgcolor= "#FFFFFF" > Time </td>
&LT;TD width= "440" align= "center" bgcolor= "#FFFFFF" > Address </td>
</tr>
<?php
while ($rs =mysql_fetch_array ($res))
{
?>
<tr>
&LT;TD align= "center" bgcolor= "#FFFFFF" ><?php echo $rs [' r_name '];? ></td>
&LT;TD align= "center" bgcolor= "#FFFFFF" ><?php Echo Date ("Y-m-d h:i:s", $rs [' r_time ']);?></td>
&LT;TD align= "center" bgcolor= "#FFFFFF" ><a href= "<?php echo $rs [' R_url '];? > "target=" _blank > <?php echo $rs [' R_url '];? ></a></td>
</tr>
<?php
}
?>
</table>
<table width= "border=" 0 "align=" center "cellspacing=" 1 "bgcolor=" #CCCCCC "style=" margin-top:20px; margin-bottom:20px; " >
<tr>
&LT;TD align= "center" bgcolor= "#FFFFFF" ><?php echo $pageurl;? ></td>
</tr>
</table>
<?php
}else{
?>
<table width= "border=" "0" align= "center" cellspacing= "1" bgcolor= "#CCCCCC" style= "margin-top:6px"; >
<tr>
&LT;TD width= "219" align= "center" bgcolor= "#FFFFFF" > Spider </td>
&LT;TD width= "574" align= "center" bgcolor= "#FFFFFF" > Statistics </td>
</tr>
<?php
while ($rs =mysql_fetch_array ($res))
{
?>
<tr>
&LT;TD align= "center" bgcolor= "#FFFFFF" ><?php echo $rs [' R_name ']?></td>
&LT;TD align= "center" bgcolor= "#FFFFFF" ><?php echo $rs [' CT ']; ></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
<table width= "border=" "0" align= "center" cellspacing= "1" bgcolor= "#CCCCCC" style= "margin-top:6px"; >
<tr>
&LT;TD align= "center" bgcolor= "#FFFFFF" > Links: <a href= "http://www.jianlila.com" target= "_blank" > recommend the ceremony </a > <a href= "http://www.aiwobama.com" target= "_blank" > Love my parents </a> <a href= "Http://www.heikediguo.net" > Hacker Empire </a></td>
</tr>
</table>
</body>
Related Article

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.