So yesterday, I did it seriously. I have more features and can perform statistical analysis on various search engines. It can be viewed in multiple time periods. In fact, the code is very simple. For the sake of simplicity, the code is compressed to 6 K. divided into 6 files
1. installer spilder_install.php
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> install the plug-in </title>
</Head>
<? Php
If ($ _ POST ['act '] = 'install') // if it is installed
{
$ Mysql_host = trim ($ _ POST ['mysql _ host']); // obtain the host
$ Mysql_user = trim ($ _ POST ['mysql _ user']); // get the user name
$ Mysql_pwd = trim ($ _ POST ['mysql _ pwd']); // obtain the password
$ Mysql_db = trim ($ _ POST ['mysql _ db']); // Database
$ Table_prefix = trim ($ _ POST ['table _ prefix']); // get the prefix
If ($ link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pwd ))
{
Echo "the connection to the server is successful !................. <Br> ";
}
Else
{
Echo "<script> alert ('link error! Check the database server configuration! '); History. go (-1); </script> ";
}
If (mysql_select_db ($ mysql_db, $ link ))
{
Echo "the database is connected successfully !............. <Br> creating a table... <br> ";
}
$ SQL = "CREATE TABLE 'spilder _ sp_count '(
'Id' bigint (20) not null auto_increment,
'R _ time' int (11) not null,
'R _ name' varchar (50) not null,
'R _ url' varchar (200) not null,
Primary key ('id ')
) ENGINE = MyISAM default charset = gb2312 AUTO_INCREMENT = 4;
";
Mysql_query ("drop table if exists '". $ table_prefix. "sp_count';"); // delete an existing
$ SQL = str_replace ("spilder _", $ table_prefix, $ SQL); // Replace the prefix
If (mysql_query ($ SQL ))
{
Echo "table created successfully! Writing File ";
}
$ F = file_get_contents ("spilder_config.php"); // get the 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! The spider statistics program is successfully installed <a href = \ "index. php \"> View </a> ";
Exit ();
}
?>
<Body>
<Table width = "600" border = "0" align = "center">
<Tr>
<Td align = "center"> spider statistics viewer </td>
</Tr>
</Table>
<Form method = "post">
<Table width = "600" border = "0" align = "center" cellspacing = "0">
<Tr>
<Td width = "280"> </td>
<Td width = "610"> Start installation </td>
</Tr>
<Tr>
<Td align = "right"> server: </td>
<Td> <input name = "mysql_host" type = "text" id = "mysql_host" value = "localhost"/>
(Usually do not change) </td>
</Tr>
<Tr>
<Td align = "right"> User name: </td>
<Td> <input type = "text" name = "mysql_user" id = "mysql_user"/> </td>
</Tr>
<Tr>
<Td align = "right"> password: </td>
<Td> <input type = "password" name = "mysql_pwd" id = "mysql_pwd"/> </td>
</Tr>
<Tr>
<Td align = "right"> Database: </td>
<Td> <input type = "text" name = "mysql_db" id = "mysql_db"/> </td>
</Tr>
<Tr>
<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>
<Td align = "right"> password management: </td>
<Td> <input type = "password" name = "sp_admin" id = "sp_admin"/> </td>
</Tr>
<Tr>
<Td align = "right"> </td>
<Td> <input type = "submit" name = "button" id = "button" value = "Install"/> </td>
</Tr>
</Table>
</Form>
</Body>
</Html>
2. Spider Record Files
Copy codeThe Code is as follows:
<? Php
Require ("spilder_config.php"); // call the configuration file
$ Link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pwd) or die ("server connection error"); // link to the database
Mysql_select_db ($ mysql_db, $ link) or die ('database connection error ');
$ Searchbot = get_naps_bot ();
If ($ searchbot)
{
Date_default_timezone_set ('prc'); // you can specify 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 'bot bot ';
} Elseif (strpos ($ useragent, 'msnbot ')! = False ){
Return 'msnbot ';
} Elseif (strpos ($ useragent, 'slurp ')! = False ){
Return 'yahoobot ';
} Elseif (strpos ($ useragent, 'baidider ider ')! = False ){
Return 'baidider ider ';
} 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. view the spider statistics File
Copy codeThe Code is as follows:
<? Php
Session_start ();
Require ("spilder_config.php ");
If ($ _ GET ['ac'] = 'logout ')
{
$ _ SESSION ['ss _ sp_admin'] = ''; // clear
}
If ($ _ GET ['SP _ admin_login '])
{
If ($ _ GET ['SP _ admin_login '] = $ sp_admin)
{
$ _ SESSION ['ss _ sp_admin'] = $ sp_admin;
}
}
Date_default_timezone_set ('prc'); // you can specify the default time zone.
$ Day_start = strtotime (date ("Ymd"). "000001"); // the start time of a day.
$ Day_out = strtotime (date ("Ymd"). "235959"); // end time of a day
$ Day = 3600*24; // The time of the day
$ Link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pwd) or die ("server connection error ");
Mysql_select_db ($ mysql_db, $ link) or die ('database connection error'); // connect to the 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) // Delete 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) // clear the category
{
$ _ SESSION ['ss _ ss'] = '';
} Else
{
$ _ SESSION ['ss _ ss'] = $ ss;
}
}
$ Ss = $ _ SESSION ['ss _ ss'];
If ($ ss = 1)
{
$ Ss = 'baidider ider ';
} Elseif ($ ss = 2)
{
$ Ss = 'bot bot ';
} 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 the time classification statistics
If ($ t = 0) // time
{
If (empty ($ _ SESSION ['ss _ ss'])
{
$ SQL = "select * from {$ table_prefix} sp_count order by id desc"; // latest situation
$ Sql2 = "select count (*) from {$ table_prefix} sp_count ";
} Else
{
$ SQL = "select * from {$ table_prefix} sp_count where r_name = '$ ss' order by id desc ";
$ Sql2 = "select count (*) from {$ table_prefix} sp_count where r_name = '$ ss '";
}
$ Rscount = mysql_query ($ sql2 );
$ Rscount = @ mysql_fetch_array ($ rscount );
$ Rscount = $ rscount [0]; // obtain the total number of records
$ Page = intval (trim ($ _ GET ['page']); // the current page number.
$ Pagesize = 30; // number of records per page
$ Pagecount = ceil ($ rscount/$ pagesize); // obtain the total number of pages
$ Pageurl = "";
If ($ page <= 1)
{
$ Page = 1;
$ Pageurl. = "homepage previous page ";
} Else
{
$ Pageurl. = "<a href = '? Page = 1 & ss = ". $ ss." '> homepage </a> <a href = '? Ss = ". $ ss." & page = ". ($ page-1)." '> previous page </a> ";
}
If ($ page> = $ pagecount)
{
$ Page = $ pagecount;
$ Pageurl. = "last page of the next page ";
} Else
{
$ Pageurl. = "<a href = '? Ss = ". $ ss." & page = ". ($ page + 1)." '> next page </a> <a href = '? Ss = ". $ ss." & page = ". $ pagecount." '> last page </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 daily 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_name ";
} 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_name ";
} Elseif ($ t = 3) // view the previous 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_name ";
} Elseif ($ t = 4) // View statistics for seven days
{
$ 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_name ";
}
Elseif ($ t = 5) // view
{
$ 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_name ";
} Elseif ($ t = 6) // view the 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_name ";
}
$ Res = mysql_query ($ SQL); // or die ("install the 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">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> display spider records </title>
<Style type = "text/css">
Td {font-size: 14px ;}
A, a: link {text-decoration: none; color: #000 ;}
A: hover {color: # F00 ;}
</Style>
</Head>
<Body>
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC" style = "margin-bottom: 6px;">
<Tr>
<Td height = "28" align = "center" bgcolor = "#66CC00"> </Tr>
</Table>
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC">
<Tr>
<Td width = "65" height = "38" bgcolor = "# FFFFFF"> View categories </td>
<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" & gt;
<A href = "? T = 0 "> time </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 days </a>
<A href = "? T = 5 "> 90 days </a>
</Td>
</Tr>
</Table>
<? Php
If ($ _ SESSION ['ss _ sp_admin'] = $ sp_admin)
{
?>
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC" style = "margin-top: 12px; margin-bottom: 12px; ">
<Tr>
<Td width = "208" align = "right" bgcolor = "# FFFFFF"> management <a href = "? Act = logout "> quit </a> </td>
<Td width = "585" align = "center" bgcolor = "# FFFFFF">
<A href = "? Act = del & dt = 0 "onclick =" return confirm ('Confirm clearing ') "> clear </a>
<A href = "? Act = del & dt = 1 "onclick =" return confirm ('Are you sure you want to delete? ') "> 30 days ago </a>
<A href = "? Act = del & dt = 2 "onclick =" return confirm ('Are you sure you want to delete? ') "> 60 days ago </a>
<A href = "? Act = del & dt = 3 "onclick =" return confirm ('Are you sure you want to delete? ') "> 90 days ago </a>
<A href = "? Act = del & dt = 4 "onclick =" return confirm ('Are you sure you want to delete? ') "> 180 days ago </a>
<A href = "? Act = del & dt = 5 "onclick =" return confirm ('Are you sure you want to delete? ') "> 360 days ago </a> </td>
</Tr>
</Table>
<? Php
}
?>
<? Php
If ($ t = 0)
{
?>
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC" style = "margin-top: 6px;">
<Tr>
<Td width = "133" align = "center" bgcolor = "# FFFFFF"> spider </td>
<Td width = "217" align = "center" bgcolor = "# FFFFFF"> time </td>
<Td width = "440" align = "center" bgcolor = "# FFFFFF"> address </td>
</Tr>
<? Php
While ($ rs = mysql_fetch_array ($ res ))
{
?>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <? Php echo $ rs ['r _ name'];?> </Td>
<Td align = "center" bgcolor = "# FFFFFF"> <? Php echo date ("Y-m-d H: I: s", $ rs ['r _ time']);?> </Td>
<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 = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC" style = "margin-top: 20px; margin-bottom: 20px; ">
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <? Php echo $ pageurl;?> </Td>
</Tr>
</Table>
<? Php
} Else {
?>
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC" style = "margin-top: 6px;">
<Tr>
<Td width = "219" align = "center" bgcolor = "# FFFFFF"> spider </td>
<Td width = "574" align = "center" bgcolor = "# FFFFFF"> Statistics </td>
</Tr>
<? Php
While ($ rs = mysql_fetch_array ($ res ))
{
?>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <? Php echo $ rs ['r _ name']?> </Td>
<Td align = "center" bgcolor = "# FFFFFF"> <? Php echo $ rs ['ct '];?> </Td>
</Tr>
<? Php
}
?>
</Table>
<? Php
}
?>
<Table width = "800" border = "0" align = "center" cellspacing = "1" bgcolor = "# CCCCCC" style = "margin-top: 6px;">
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> links: <a href = "http://www.jianlila.com" target = "_ blank"> recommendations </a> <a href = "http://www.aiwobama.com" target = "_ blank"> love my parents </> <a href = "http://www.heikediguo.net"> matrix </a> </td>
</Tr>
</Table>
</Body>
</Html>