Home Backend Development PHP Tutorial The PHP spider statistics plug-in can be used as long as you have mysql_PHP tutorial

The PHP spider statistics plug-in can be used as long as you have mysql_PHP tutorial

Jul 21, 2016 pm 03:33 PM
mysql php one time by Function Can Available plug-in yesterday statistics spider

So I did it seriously yesterday. It has more functions and can perform statistical analysis on various search engines. Can be viewed over multiple time periods. In fact, the code is very simple. In order to be more concise, the code is compressed to 6k. It is divided into 6 files
1. Installer spilder_install.php

Copy the code The code is as follows:





Install plug-in

if($_POST[ 'act']=='install')//If installing
{
$mysql_host=trim($_POST['mysql_host']);//Get the host
$mysql_user=trim($_POST ['mysql_user']);//Get the username
$mysql_pwd=trim($_POST['mysql_pwd']);//Get the 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 "Connection to server successful!.............
";
}
else
{
echo "";
}
if(mysql_select_db($mysql_db,$link))
{
echo "Connecting to database successfully!............
Creating 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 existing
$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 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 Jianli spider statistics program was installed successfullyView";
exit();
}
?>
< body>




Recommended Spider Statistics Viewer










(Generally no need to change)












< /tr>












< ;/table>




2. Spider record file
Copy code The code is as follows:

require(" spilder_config.php");//Calling the configuration file
$link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd) or die("Server connection error");//Linking the 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 file
Copy code The code is as follows:

session_start();
require("spilder_config.php");
if($_GET['act']=='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'); //Set the default time zone
$day_start=strtotime(date("Ymd")."000001");//The start time of the day
$day_out=strtotime(date("Ymd")."235959");//The end time 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('Error linking database');//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)//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 category 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)//Time situation
{
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];//Get the total number of records
$page=intval(trim($_GET ['page']));//Current page number
$pagesize=30;//Number of records per page
$pagecount=ceil($rscount/$pagesize);//Get the total number of pages
$pageurl="";
if($page<=1)
{
$page=1;
$pageurl.=" Home page previous page";
}else
{
$pageurl .=" Homepage Previous page";
}
if($page>=$pagecount)
{
$page=$pagecount;
$pageurl .=" Next page Last page";
}else
{
$pageurl .=" Next page Last page";
}
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 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 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)//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_name ";
}
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_name ";
}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_name ";
}
$res=mysql_query($sql);// or die("请先安装程序安装");
?>



显示蜘蛛记录情况



Start installation
Server:
Username:
Password:
Database:
Table prefix:
Manage password:




荐礼啦 蜘蛛查看器








分类查看  
所有的 
百度  
谷歌  
必应 
雅虎 
搜狗  
搜搜 
有道
 
时时  
今天 
昨天 
前天 
七天 
30天 
90天 

if($_SESSION['ss_sp_admin']==$sp_admin)
{
?>





管理  退出   
清空  
30天前  
60天前  
90天前   
180天前  
360天前

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






while($rs=mysql_fetch_array($res))
{
?>





}
?>
蜘蛛 时间 地址






}else{
?>





while($rs=mysql_fetch_array($res))
{
?>




}
?>
蜘蛛 统计

}
?>




友情链接:荐礼啦 爱我爸妈 黑客帝国



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/322528.htmlTechArticle于是昨天便认真的做了一下,功能多一点,可以对各种搜索引擎统计分析。可以在多个时间段进行查看。其实代码很简单,为了更简洁些,...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

See all articles