发款php蜘蛛统计插件只要有mysql就可用

于是昨天便认真的做了一下,功能多一点,可以对各种搜索引擎统计分析。可以在多个时间段进行查看。其实代码很简单,为了更简洁些,代码压缩到6k.分为6个文件
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>安装插件</title>
</head>
<?php
if($_POST['act']=='install')//如果是安装
{
$mysql_host=trim($_POST['mysql_host']);//获取主机
$mysql_user=trim($_POST['mysql_user']);//获取用户名
$mysql_pwd=trim($_POST['mysql_pwd']);//获取密码
$mysql_db=trim($_POST['mysql_db']);//数据库
$table_prefix=trim($_POST['table_prefix']);//获取前缀
if($link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd))
{
echo "连接服务器成功!.................<br>";
}
else
{
echo "<script>alert('链接出错!请检查数据库服务器配置!');history.go(-1);</script>";
}
if(mysql_select_db($mysql_db,$link))
{
echo "连接数据库成功!.............<br>正在创建表................<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`;");//删除已存在
$sql=str_replace("spilder_",$table_prefix,$sql);//替换前缀
if(mysql_query($sql))
{
echo "表创建成功!正在写入文件";
}
$f=file_get_contents("spilder_config.php");//获取配置内容
$f=str_replace(" ","",$f);//去除空格
$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 href=https://www.jb51.net/article/\"index.php\">查看</a>";
exit();
}
?>
<body>
<table>
<tr>
<td>荐礼啦 蜘蛛统计查看器</td>
</tr>
</table>
<form method="post">
<table cellspacing="0">
<tr>
<td>&nbsp;</td>
<td>开始安装</td>
</tr>
<tr>
<td>服务器:</td>
<td><input type="text" value="localhost" />
(一般不用改)</td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" /></td>
</tr>
<tr>
<td>数据库:</td>
<td><input type="text" /></td>
</tr>
<tr>
<td>表前缀:</td>
<td><input type="text" value="spilder_" />
<input type="hidden" value="install" /></td>
</tr>
<tr>
<td>管理密码:</td>
<td><input type="password" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="安装" /></td>
</tr>
</table>
</form>
</body>
</html>


2.蜘蛛记录文件

复制代码 代码如下:


<?php
require("spilder_config.php");//调用配置文件
$link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd) or die("服务器连接出错");//链接数据库
mysql_select_db($mysql_db,$link) or die('数据库连接出错');
$searchbot = get_naps_bot();
if($searchbot)
{
date_default_timezone_set('PRC'); //设置默认时区
$r_time=strtotime(date("Y-m-d H:i:s"));//最后更新时间
$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.蜘蛛统计查看文件

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/7a86b6363e6d4aca7ddfe4700fa25d1a.html