PHP spider statistics plugin is available as long as you have mysql

  • 2020-03-31 21:09:42
  • OfStack

So yesterday was done seriously, a little more function, can all sorts of search engine statistical analysis. You can view it over multiple time periods. In fact, the code is very simple, in order to be more concise, the code is compressed to 6k. Divided into 6 files
1. Spilder_install.php
 
<!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> Installing a plug-in </title> 
</head> 
<?php 
if($_POST['act']=='install')//If it's installation
{ 
$mysql_host=trim($_POST['mysql_host']);//Access to the host
$mysql_user=trim($_POST['mysql_user']);//Get username
$mysql_pwd=trim($_POST['mysql_pwd']);//To get the password
$mysql_db=trim($_POST['mysql_db']);//The database
$table_prefix=trim($_POST['table_prefix']);//To obtain a prefix
if($link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd)) 
{ 
echo " Connection to server successful! .................<br>"; 
} 
else 
{ 
echo "<script>alert(' Wrong link! Please check the database server configuration! ');history.go(-1);</script>"; 
} 
if(mysql_select_db($mysql_db,$link)) 
{ 
echo " Database connection successful! .............<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 already exists
$sql=str_replace("spilder_",$table_prefix,$sql);//Replace the 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 the blank 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 " A: congratulations! Spider statistics program installed successfully  <a href="index.php"> To view </a>"; 
exit(); 
} 
?> 
<body> 
<table width="600" border="0" align="center"> 
<tr> 
<td align="center"> Commend ceremony!   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 the installation </td> 
</tr> 
<tr> 
<td align="right"> Server: </td> 
<td><input name="mysql_host" type="text" id="mysql_host" value="localhost" /> 
( You don't have to change it )</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"> Management password: </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=" The installation " /></td> 
</tr> 
</table> 
</form> 
</body> 
</html> 

2. Spider records
 
<?php 
require("spilder_config.php");//Invoke 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 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 file
 
<?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 default time zone
$day_start=strtotime(date("Ymd")."000001");//The start of the day
$day_out=strtotime(date("Ymd")."235959");//The end of the day
$day=3600*24;//Time of day
$link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd) or die(" Server connection error "); 
mysql_select_db($mysql_db,$link) or die(' Linked database error ');//Connect to 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)//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 the data
} 
} 
} 
$ss=intval($_GET['ss']); 
if($ss>0)//View classification statistics
{ 
if($ss==999)//Empty the classification
{ 
$_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 breakdown statistics
if($t==0)//All the cases
{ 
if(empty($_SESSION['ss_ss'])) 
{ 
$sql =" select * from {$table_prefix}sp_count order by id desc ";//The 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];//Gets the total number of records
$page=intval(trim($_GET['page']));//The current number of pages
$pagesize=30;//Number of records per page
$pagecount=ceil($rscount/$pagesize);//Get total pages
$pageurl=""; 
if($page<=1) 
{ 
$page=1; 
$pageurl.="  Home page   The previous page "; 
}else 
{ 
$pageurl .=" <a href='?page=1&ss=".$ss."'> Home page </a>  <a href='?ss=".$ss."&page=".($page-1)."'> The previous page </a>"; 
} 
if($page>=$pagecount) 
{ 
$page=$pagecount; 
$pageurl .="  The next page    back "; 
}else 
{ 
$pageurl .=" <a href='?ss=".$ss."&page=".($page+1)."'> The next page </a>  <a href='?ss=".$ss."&page=".$pagecount."'> back </a>"; 
} 
if($page<=1) 
{ 
$page=1; 
} 
$start_rs=intval(($page-1)*$pagesize);//start
$end_rs=intval($page*$pagesize);//The end of the
$sql .=" limit {$start_rs},{$end_rs} "; 
} 
if($t==1)//Check today's day statistics
{ 
$s_time=$day_start;//The start time
$e_time=$day_out;//The end of 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;//The end of the
$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)//Check the previous day's 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)//Look at 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_name "; 
} 
elseif($t==5)//Check 30 days old
{ 
$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)//Look at 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 the program first <A href = 'spilder_install. PHP> Installation </ 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> Shows the spider recording the situation </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"><h1><a href="http://www.jianlila.com" target="_blank"> Commend ceremony! </a>  Spider viewer </h1></td> 
</tr> 
</table> 
<table width="800" border="0" align="center" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<td width="65" height="38" bgcolor="#FFFFFF"> Classification of view </td> 
<td width="403" align="center" bgcolor="#FFFFFF">   
<a href="?ss=999"> All of the </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> 
<td width="322" bgcolor="#FFFFFF">  
<a href="?t=0"> All the 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 day </a>  
<a href="?t=5">90 day </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"> exit </a>   </td> 
<td width="585" align="center" bgcolor="#FFFFFF"> 
<a href="?act=del&dt=0" onclick="return confirm(' Sure to empty ')"> empty </a>   
<a href="?act=del&dt=1" onclick="return confirm(' Sure to delete? ')">30 Days ago, </a>   
<a href="?act=del&dt=2" onclick="return confirm(' Sure to delete? ')">60 Days ago, </a>   
<a href="?act=del&dt=3" onclick="return confirm(' Sure to delete? ')">90 Days ago, </a>    
<a href="?act=del&dt=4" onclick="return confirm(' Sure to delete? ')">180 Days ago, </a>   
<a href="?act=del&dt=5" onclick="return confirm(' Sure 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"> The 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"> The spider </td> 
<td width="574" align="center" bgcolor="#FFFFFF"> statistical </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"> Commend ceremony! </a> <a href="http://www.aiwobama.com" target="_blank"> Love my parents </a> <a href="http://www.heikediguo.net"> The matrix </a></td> 
</tr> 
</table> 
</body> 
</html> 

Related articles: