极简单/简陋的wordpress插件:网站访客追踪记录 v0.0.2

这是对旧文中提到的wordpress访客记录的一次升级版,照样很简陋,算作给自己玩的吧;谁需要的话,也可以拿去玩。

源码

<?php
/*
Plugin Name: fs trace
Plugin URI: http://blog.path8.net/
Description: This plugin will trace all visitor's visit action.
Version: 0.0.2
Author: fengyqf
Author URI: http://blog.path8.net/
*/

/*  
    Copyright 2008  fengyqf  (email : fengyqf@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

function fstrace_by_fengyqf(){
  global $wpdb;

  $url=mysql_escape_string(substr($_SERVER["REQUEST_URI"],0,200));
  $referer=mysql_escape_string(substr($_SERVER["HTTP_REFERER"],0,200));
  $cookie=mysql_escape_string(substr($_SERVER["HTTP_COOKIE"],0,250));
  $client=mysql_escape_string(substr($_SERVER["HTTP_USER_AGENT"],0,200));
  if(getenv('HTTP_CLIENT_IP')) {
    $ip = getenv('HTTP_CLIENT_IP');
  } elseif(getenv('HTTP_X_FORWARDED_FOR')) {
    $ip = getenv('HTTP_X_FORWARDED_FOR');
  } elseif(getenv('REMOTE_ADDR')) {
    $ip = getenv('REMOTE_ADDR');
  } else {
    $ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
  } 
  $ip=mysql_escape_string(substr($ip,0,16));
  $sql="insert into `log`.`wp_trace_{$wpdb->prefix}`(`referer`,`url`,`unixtime`,`ip`,`client`,`cookie`) 
          values('{$referer}','{$url}',".time().",'{$ip}','{$client}','{$cookie}')";
  $wpdb->query($sql);
  if($wpdb->last_error){
    echo "<script type=\"text/javascript\">alert('Something Wrong! get messages at page bottom. | 出错了,到页底查看详细');</script><h1>fs trace message</h1><p>You Need to Create a table for <strong>fs trace</strong>, to log your visitor active. this table was in database <i>log</i>, you can change the wp-plugin <strong>fs trace</strong> file, in wp pannel - plugins - edit - fs trace, find the line \"  \$sql=\"insert into `log`.`wp_trace_{$wpdb->prefix}`... \", and change it to <pre>\$sql=\"insert into `wp_trace_{$wpdb->prefix}`...</pre> (yes, delete <i>`log`.</i>),and sava it </p>
<p>您需要创建一个表,用于 <strong>fs trace</strong>存储wordpress的将追踪记录. 该表默认位于数据库 log 中。如果您不方便创建一个名为log的数据库,可以将该表放在当前数据库中,只是要修改一下<strong>fs trace</strong>源码了,到wordpress仪表盘 - 插件 - 编辑 - fs trace, 找到这样一行  \"  \$sql=\"insert into `log`.`wp_trace_{$wpdb->prefix}`... \", 改成 <pre>\"insert into `wp_trace_{$wpdb->prefix}`...</pre> (就是删除 <i>`log`.</i>),保存。 </p>
<p>create the table as below/建表语句如下</p>
<pre>use `log`; 
CREATE TABLE `wp_trace_{$wpdb->prefix}` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `referer` varchar(200) NOT NULL DEFAULT '',
  `url` varchar(200) NOT NULL DEFAULT '',
  `unixtime` int(10) unsigned NOT NULL DEFAULT '0',
  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ip` varchar(16) NOT NULL DEFAULT '',
  `client` varchar(200) NOT NULL DEFAULT '',
  `cookie` varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;</pre> <p>grant the mysql user INSERT privileges at least;In fact, INSERT is enough. </p> <p>为 mysql 用户赋权限,至少需要对该表的INSERT权限;事实上只需要insert权限即可. </p> <p> Alert by the plugin <strong>fs trace</strong> </p>";
//    var_dump($wpdb);
  }
}
add_action('wp_footer','fstrace_by_fengyqf');
?>

下载源码

使用说明

wordpress后台,通过上传zip文件方式上传该插件,(或解压后,连目录上传到wordpress下 wp-content/plugins/ 目录),启用插件,然后到打开前台任意页面,照错误提示操作。消息提示有中英两种语言。提示文字可能因为您的模板关系而排版错乱,看起来有些费力。

本插件不会自己创建数据表,需要您按消息提示手工创建。

本表默认在一个名为log的数据库里,因为追踪表通常会比较大,可以减少wordpress主数据库体积,主要是方便备份。单独。如果不方便创建这个数据库(如在虚拟主机上,主机商通常只给一个数据库),可以修改本插件源码,上述错误消息里也有提示。

发表评论?

0 条评论。

发表评论