Go to comments ↓ Home » Blog

反垃圾评论:WP Anti Spam + Spam To Blacklist

Wordpress这年头 Spam(垃圾评论)越来越猖獗,在我们使用的 WordPress 平台亦是如此。

当然,万能的 WordPress 对付 Spam 的方法也有很多。
个人并不喜欢使用验证码、算术题之类的,那虽然很有效,但会给评论者造成麻烦。
而评论审核则会影响体验,仅在离开较长时间才会打开。

再此分享一下我的反垃圾评论方案:免插件的WP Anti Spam + Spam To Blacklist 插件。

wordpress 反垃圾评论

这是两个月内收到的 Spam,该清理了~

WP Anti Spam 小墙,免插件的反 Spam 方案

我之前一直是用着 wp 自带的 Akismet ,使用黑名单机制,但无论对机器还是人肉 Spam 都很不错,还能自动学习。
不过时不时会把一些正常的评论误杀了,导致经常要跑去检查垃圾评论- -。

后来发现了这个 WP Anti Spam ,昵称小墙是免插件拦截垃圾评论的利器
来自低调的大师 Willin Kan ,周围的很多朋友也在用着,评价很高。

小墙原理和功能

其原理可以简单理解为:添加一个隐藏的资料框(属性为 display:none 的 textarea),因为用户是看不到的,如果该区域被填满则判断为 Spam。
还也能判断一些手动方式的。

WP Anti Spam 小墙

另外还在后台提供了spam 的基本资料,包含请求( REQUEST_URI )、来路( HTTP_REFERER )、IP、操作方式,,可提供下一步加强防护的参考。(见上图)

使用 WP Anti Spam 小墙的方法

效果出色,还免插件,没什么好犹豫的。
将以下代码复制到主题的 functions.php 中即可。

/* <<小牆>> Anti-Spam v1.81 by Willin Kan. */
//建立
class anti_spam {
  function anti_spam() {
    if ( !current_user_can('level_0') ) {
      add_action('template_redirect', array($this, 'w_tb'), 1);
      add_action('init', array($this, 'gate'), 1);
      add_action('preprocess_comment', array($this, 'sink'), 1);
    }
  }
  //設欄位
  function w_tb() {
    if ( is_singular() ) {
      ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=([\"\'])comment([\"\'])(.+)/textarea>#",
      "textarea$1name=$2w$3$4/textarea><textarea cols="\"100%\"" rows="\"4\"" name="\"comment\""></textarea>",$input);') );
    }
  }
  //檢查
  function gate() {
    if ( !empty($_POST['w']) && empty($_POST['comment']) ) {
      $_POST['comment'] = $_POST['w'];
    } else {
      $request = $_SERVER['REQUEST_URI'];
      $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER']         : '隱瞞';
      $IP      = isset($_SERVER["HTTP_VIA"])     ? $_SERVER["HTTP_X_FORWARDED_FOR"]. ' (透過代理)' : $_SERVER["REMOTE_ADDR"];
      $way     = isset($_POST['w'])              ? '手動操作'                       : '未經評論表格';
      $spamcom = isset($_POST['comment'])        ? $_POST['comment']                : null;
      $_POST['spam_confirmed'] = "請求: ". $request. "\n來路: ". $referer. "\nIP: ". $IP. "\n方式: ". $way. "\n內容: ". $spamcom. "\n -- 記錄成功 --";
    }
  }
  //處理
  function sink( $comment ) {
    if ( !empty($_POST['spam_confirmed']) ) {
      if ( in_array( $comment['comment_type'], array('pingback', 'trackback') ) ) return $comment; //不管 Trackbacks/Pingbacks
      //方法一: 直接擋掉, 將 die(); 前面兩斜線刪除即可.
      //die();
      //方法二: 標記為 spam, 留在資料庫檢查是否誤判.
      add_filter('pre_comment_approved', create_function('', 'return "spam";'));
      $comment['comment_content'] = "[ 小牆判斷這是Spam! ]\n". $_POST['spam_confirmed'];
    }
    return $comment;
  }
}
$anti_spam = new anti_spam();
// -- END ----------------------------------------

另外,我们可以看到很多 Spam 都是直接向 wp-comments-post.php 发出请求。
由于我使用了 Willin 大师的 Ajax comments,所以也可以把 wp-comments-post.php 给重命名了,这基本上阻挡了所有的机器 Spammer,不过没有 Spammer的日子也寂寞,哈哈。

Spam To Blacklist 插件,对抗人肉 Spam 的利器

这是来自 jiucool 同学的原创插件。
Spam To Blacklist 这个插件的作用是,在用户手动标记为垃圾评论时,自动将其 Email 和 URL 添加到评论黑名单。

小墙在对付机器 Spam 之类的无比强大,但并不是采用像 Akismet 那种黑名单机制,人肉的 Spammer 容易漏网。

这个Spam To Blacklist 刚好能补充这方便的不足,人肉对抗人肉,插件是把操作给简化了
消灭那些 xx Seo,xx推广,xx网站 – -。

为了更新方便,请移步到 Spam To Blacklist 的主页下载。

下载插件后,解压完成将其上传至 /wp-content/plugins/ 目录,然后启用之即可,无需其他操作!

这就是我目前的反垃圾评论方案,你的呢?欢迎分享经验^ ^

» 转载请以超链接形式注明来源:A.shun Blog » 《反垃圾评论:WP Anti Spam + Spam To Blacklist》
» 本文链接地址:http://shun.im/21377

» 本文采用 BY-NC-SA 协议进行授权。
» 建议通过 Rss( Feedly | Feedburner | Feedsky )方式及时获取更新。
  1. 小墙是个好东西,一直很感激Willin 大师。 ➡

    Opera 10.60 Opera 10.60 Windows 7 Windows 7
    #1
    @
  2. 很早就用过,但是后来和主题有点冲突,还在找毛病

    Firefox 3.6.8 Firefox 3.6.8 Windows 7 Windows 7
    #2
    @
  3. 人肉对人肉,嘎嘎 😛 😛

    Mozilla Compatible Mozilla Compatible Unknown Unknown
    #3
    @
  4. 哈哈,我这点子不错吧,jiucool V5,willin V5

    Firefox 3.6.8 Firefox 3.6.8 Windows XP Windows XP
    #4
    @
  5. 人肉对人肉~~~
    willin大师造福了很多人啊

    Firefox 3.6.8 Firefox 3.6.8 Windows XP Windows XP
    #5
    @
  6. 请求,来路是1.81才有的么,我用的1.8

    Google Chrome 6.0.453.0 Google Chrome 6.0.453.0 Windows XP Windows XP
    #6
    @
  7. 深深受益中 😮

    Firefox 3.6.8 Firefox 3.6.8 Ubuntu 10.04 x64 Ubuntu 10.04 x64
    #7
    @
  8. 最近一直都是广告留言,试过几个插件都不行,现在我还是开着审核的,我也换这个用用 😐
    ps,我换个邮箱填了 ❗

    ChromePlus 1.4.0.0 ChromePlus 1.4.0.0 Windows 7 Windows 7
    #8
    @
  9. 小墙和我用的主题参数冲突,我有不知道是哪个参数,悲剧啊…

    Firefox 3.6.8 Firefox 3.6.8 Windows 7 Windows 7
    #9
    @
  10. Akismet还不错,就是有时误判 ❗

    Firefox 3.6.8 Firefox 3.6.8 Windows 7 Windows 7
    #10
    @
  11. 有句话说得对,没有SPAM也挺寂寞

    Google Chrome 5.0.375.125 Google Chrome 5.0.375.125 Windows XP Windows XP
    #11
    @
  12. 我博客的Spam基本是全字母的,用Input Some Chinese,挺好。 😀

    Firefox 3.6 Firefox 3.6 Windows 7 Windows 7
    #12
    @
  13. 第二次看这段代码,大概理解了工作方式,把原来name=”comment”的输入框隐藏再加上一个name=”w”的输入框,如果w有内容而comment没内容就说明不是spam(人肉的不能检测),一般软件是直接向comment发送信息

    Google Chrome 6.0.477.0 Google Chrome 6.0.477.0 Windows 7 Windows 7
    #13
    @
  14. 我用的小蜜蜂和小墙是一个原理

    Firefox 3.6.8 Firefox 3.6.8 Windows XP Windows XP
    #14
    @
  15. 好东西啊,垃圾评论真是件头痛的事情

    我启动spam_to_blacklist插件的时候总是报错,奇怪啊

    Firefox 3.5.7 Firefox 3.5.7 Windows XP Windows XP
    #15
    @
  16. 现在一直只用小墙

    ChromePlus 1.4.0.0 ChromePlus 1.4.0.0 Windows 7 Windows 7
    #16
    @
  17. 装上去试试 看来垃圾评论很多。

    TheWorld Browser TheWorld Browser Windows 7 x64 Edition Windows 7 x64 Edition
    #17
    @
  18. 我还是用自带的,现在评论已经不多了,spam却越来越多。

    Firefox 3.6.8 Firefox 3.6.8 Windows XP Windows XP
    #18
    @
  19. 对于访量不大的个人博客来说~垃圾评论简直就是奢侈啊~哈哈~

    Firefox 3.6.8 Firefox 3.6.8 Windows 7 Windows 7
    #19
    @
    • @爱月 还是很多的,机器spam不管你的访问量,很多都是根据网址段群发的

      Opera 10.61 Opera 10.61 Windows XP Windows XP
  20. 我看到强大的评论数量了` 😀

    Firefox 3.5.11 Firefox 3.5.11 Windows XP Windows XP
    #20
    @
  21. 我的小站…暂时无需用到这种大型杀伤武器~~ 😎

    不过我是比较不喜欢用验证码之类的~ 💡

    Firefox 3.6.8 Firefox 3.6.8 Windows XP Windows XP
    #21
    @
  22. 以前经常有大量的垃圾评论,现在一天也就几条,习惯了,要是一条没有,还真没习惯,呵呵。
    PS:为啥人肉就会填那个隐藏的文本框呢?

    Internet Explorer 8.0 Internet Explorer 8.0 Windows XP Windows XP
    #22
    @
    • @世纪之光 人肉当然不填了,好像有另外的规则对付人肉,不过效果一般。
      所以用下面的辅助

      Opera 10.61 Opera 10.61 Windows XP Windows XP
  23. 自从在A5发文章,一个多星期了,同一个人天天发,我估计是他们有专门的软件吧。

    Google Chrome 5.0.375.125 Google Chrome 5.0.375.125 Windows 7 Windows 7
    #23
    @
  24. 垃圾邮件无处不在,碰到会让你遍体鳞伤 :mrgreen:

    Firefox 3.6.3 Firefox 3.6.3 Windows XP Windows XP
    #24
    @
  25. 目前spam不多,还可以处理得过来,如果人肉的评论和内容相关我还是会手下留情的,推广不容易 呵呵。
    这个插件相当于设个陷阱给机器人跳~

    Google Chrome 6.0.472.0 Google Chrome 6.0.472.0 Windows XP Windows XP
    #25
    @
  26. Lazyyyyyy

    很好的人肉对抗人肉插件,之前在Z叔叔那边也看到类似的插件~

    Maxthon 2.0 Maxthon 2.0 Windows XP Windows XP
    #26
    @
  27. 这个插件也很强大

    Maxthon 2.0 Maxthon 2.0 Windows XP Windows XP
    #27
    @
  28. 我一直用的是系统自带的反垃圾.

    Google Chrome 6.0.483.0 Google Chrome 6.0.483.0 Windows 7 Windows 7
    #28
    @
  29. 我用Akismet

    Firefox 3.6.6 Firefox 3.6.6 Windows XP Windows XP
    #29
    @
  30. 暂时还是用着akismet,还够用……

    Google Chrome 5.0.375.125 Google Chrome 5.0.375.125 Windows XP Windows XP
    #30
    @
  31. 其实我想问下有没有根据URL来spam的插件,一般发广告的都带url。

    Google Chrome 6.0.486.0 Google Chrome 6.0.486.0 Windows XP Windows XP
    #31
    @
    • @BoKeam 更加url来spam- –
      有时候访客也会发url的吧。
      而且这个功能wp自带了的,在设置>讨论里面:当一条评论有x个或更多超链接时放入等待审核队列。

      Opera 10.70 Opera 10.70 Windows XP Windows XP
  32. 先用着Akismet
    Willin大师的小墙也看过,以后考虑用不用

    Firefox 3.6.3 Firefox 3.6.3 Windows XP Windows XP
    #32
    @
  33. 原来我在哪里好像看到过小墙,当时就用了,到现在无一错判,非常好用! :roll:

    Google Chrome 5.0.375.127 Google Chrome 5.0.375.127 Windows XP Windows XP
    #33
    @
  34. Akismet我用着不错,人肉spanner倒是经常没抓到,误判倒没发现,估计是我留言数量太少了吧

    Firefox 3.6.8 Firefox 3.6.8 Windows 7 Windows 7
    #34
    @
  35. 已经在wordpress啦和某位博主的留言里介绍了,刚好有不少朋友被这个困扰

    Firefox 3.6 Firefox 3.6 Windows XP Windows XP
    #35
    @
  36. 现在没用这上了 😉

    Firefox 3.6.8 Firefox 3.6.8 Windows XP Windows XP
    #36
    @
  37. 主要是人肉的比较难对付~

    Firefox 3.6.8 Firefox 3.6.8 Windows 7 Windows 7
    #37
    @
  38. 试试先~

    Google Chrome 7.0.517.0 Google Chrome 7.0.517.0 GNU/Linux GNU/Linux
    #38
    @
  39. 看样子很不错呀。收下了。 :roll:

    Opera 10.61 Opera 10.61 Windows XP Windows XP
    #39
    @
  40. 佛山步惊云

    怎样发评论来测试这个WP Anti Spam 小墙的功能呢?求请教

    Firefox 14.0.1 Firefox 14.0.1 Windows XP Windows XP
    #40
    @

  41. 感谢分享

    Google Chrome 30.0.1599.101 Google Chrome 30.0.1599.101 Windows 7 Windows 7
    #41
    @
  42. You actually make it appear so easy with your presentation however I to find this topic to be really something that I believe I would never understand.

    It seems too complex and very wide for me. I’m looking forward
    for your next publish, I’ll try to get the grasp of it!

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #42
    @
  43. It’s going to be ending of mine day, except before
    finish I am reading this wonderful piece of writing to improve my know-how.

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #43
    @
  44. Genuinely no matter if someone doesn’t understand then its up
    to other users that they will assist, so here it occurs.

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #44
    @
  45. What’s up, after reading this remarkable post i am too happy to share my knowledge here
    with friends.

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #45
    @
  46. For latest news you have to go to see internet and on web
    I found this site as a most excellent site for hottest updates.

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #46
    @
  47. I don’t even know the way I ended up right here, but I believed this put up was once great.
    I do not know who you’re however certainly you are going to
    a famous blogger when you aren’t already. Cheers!

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #47
    @
  48. Hmm it appears like your website ate myy first comment
    (it was super long) so I guess I’ll just sum it up what I hadd written and say, I’m thoroughly enjoying your blog.
    I too amm an aspiring blog writer buut I’m still new to everything.

    Do you have any suggestions for rookie blog writers? I’d certainly appreciate it.

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #48
    @
  49. I do not know whether it’s just me or if everyone else encountering issues with your site.
    It looks like some of the text on your posts are running off the screen. Can somebody else
    please comment and let me know if this is happening to them as well?

    This could be a problem with my web browser because I’ve
    had this happen previously. Kudos

    Opera 12.17 Opera 12.17 Windows 8 x64 Edition Windows 8 x64 Edition
    #49
    @
  50. 古着屋は,当たり外れありますが、ダメージを書いてある店なので良店だと思います。
    ルイヴィトン カデナ パドロック ゴールド 艶あり 新品 南京錠 lv-002 ルイ・ヴィトン
    皆様の絶好評判を偽物スーパーコピー 時計人気専門 ショップですロレックススーパーコピーなど世界中有名なスーパーコピー 時計を格安で通販しております。N級品スーパーコピー 時計は 業界で最高な品質に挑戦します。!その達成は多数のうちの1つです。しかし、それは、完成を求めるロレックス、および彼らのエクスプローラーをそれらの成功の主要部分と考える人々の両方をガイドする冒険心を象徴します https://www.gooshop001.com/product/detail/2786.htm

    Internet Explorer 11.0 Internet Explorer 11.0 Windows 7 Windows 7
    #50
    @
Leave a Reply to 小O

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

点击这里取消回复。