<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>简单生活 —— Kevin Yang的博客 &#187; 垃圾评论</title> <atom:link href="http://www.imkevinyang.com/tags/%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba/feed" rel="self" type="application/rss+xml" /><link>http://www.imkevinyang.com</link> <description>It&#039;s all about sharing</description> <lastBuildDate>Mon, 06 Sep 2010 08:00:00 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>让博客不用Anti-Spam插件一样没有垃圾评论</title><link>http://www.imkevinyang.com/2010/02/%e8%ae%a9%e5%8d%9a%e5%ae%a2%e4%b8%8d%e7%94%a8anti-spam%e6%8f%92%e4%bb%b6%e4%b8%80%e6%a0%b7%e6%b2%a1%e6%9c%89%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba.html</link> <comments>http://www.imkevinyang.com/2010/02/%e8%ae%a9%e5%8d%9a%e5%ae%a2%e4%b8%8d%e7%94%a8anti-spam%e6%8f%92%e4%bb%b6%e4%b8%80%e6%a0%b7%e6%b2%a1%e6%9c%89%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba.html#comments</comments> <pubDate>Mon, 15 Feb 2010 17:12:00 +0000</pubDate> <dc:creator>Kevin Yang</dc:creator> <category><![CDATA[工具技巧]]></category> <category><![CDATA[AntiSpam plugin]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[博客]]></category> <category><![CDATA[垃圾评论]]></category> <category><![CDATA[表单]]></category> <category><![CDATA[评论机器人]]></category><guid isPermaLink="false">http://www.imkevinyang.com/2010/02/%e8%ae%a9%e5%8d%9a%e5%ae%a2%e4%b8%8d%e7%94%a8anti-spam%e6%8f%92%e4%bb%b6%e4%b8%80%e6%a0%b7%e6%b2%a1%e6%9c%89%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba.html</guid> <description><![CDATA[<p>写博客的人最讨厌的就是垃圾评论了。以前开博才不到半年没有装反垃圾评论插件的时候，平均一天会收到5条左右的垃圾评论，而且一看显然是机器人提交的，后来不得不找插件防着。现在网络上最常见的反垃圾评论插件就是加验证码了。让用户每次发表评论的时候都输入验证码。稍微用户体验好点的就只在用户第一次评论的时候才需要验证码，以后就不需要了。但这种方式很容易和那些缓存插件冲突，而且让用户多输入一个验证码感觉也挺无奈的。</p><p>后来我就用了WP-SpamFree插件&#8230;</p>]]></description> <content:encoded><![CDATA[<p>写博客的人最讨厌的就是垃圾评论了。以前开博才不到半年没有装反垃圾评论插件的时候，平均一天会收到5条左右的垃圾评论，而且一看显然是机器人提交的，后来不得不找插件防着。现在网络上最常见的反垃圾评论插件就是加验证码了。让用户每次发表评论的时候都输入验证码。稍微用户体验好点的就只在用户第一次评论的时候才需要验证码，以后就不需要了。但这种方式很容易和那些缓存插件冲突，而且让用户多输入一个验证码感觉也挺无奈的。</p><p>后来我就用了WP-SpamFree插件。据说这插件是利用Cookie和Javascript互相配合来实现防范垃圾评论的，细节我没有去深究，不是很清楚。之前观察过一阵子他记录的调试日志，确实是能够100%的拦截垃圾评论，没有误报。</p><p>但前阵子这个插件突然大罢工了，随便怎么评论都说我的留言有问题，通不过。经过一番瞎折腾之后，发现又无缘无故好了。但是我对这插件开始有了不信任感~</p><p>我后来就在想，与其用别人现成的插件来实现反垃圾评论，为什么不自己实现一个简单易用，而又适合自己实际情况的反垃圾评论机制呢？</p><p>我对评论机器人软件不是很熟悉，猜想大概他们会维护一个庞大的博客列表，然后定时去爬取上面的网页，分析页面，找到上面的评论表单——可能是有特征识别，也可能不管三七二十一找到表单就算，然后填写其中的各个字段，最后提交表单。所以<strong><span style="color: #008000;">如果我把评论表单的提交地址给删了，那么评论机器人找不到提交地址或者找到错误的提交地址，就无法成功提交评论了。那真正的用户如何评论呢？我可以在表单加载完之后立刻通过Javascript动态更新评论表单的提交地址就行了</span></strong>。</p><p>代码修改非常简单，打开主题文件夹中，找到评论表单所在的模板文件，一般是在comments.php中。</p><pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">action</span><span class="kwrd">="/wp-comments-post.php"</span> <span class="attr">method</span><span class="kwrd">="post"</span> <span class="attr">id</span><span class="kwrd">="commentform"</span><span class="kwrd">&gt;</span>
...
<span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span></pre><p>这是未修改之前的代码。将其action属性的值改为空字符串。然后在结束标签下面添加一行Javascript。如下所示：</p><pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">action</span><span class="kwrd">=""</span> <span class="attr">method</span><span class="kwrd">="post"</span> <span class="attr">id</span><span class="kwrd">="commentform"</span><span class="kwrd">&gt;</span>
...
<span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">="text/javascript"</span><span class="kwrd">&gt;</span>
    document.getElementById(<span class="str">"commentform"</span>).action = <span class="str">"/wp-comments-post.php"</span>;
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre><p>OK，这样代码重构完之后就和原来的一样了。</p><p>但是这样带来的问题就是，如果对方浏览器禁用了Javascript，那么他也无法评论了。对于我来说，这个比例基本可以忽略。当然，这个方法并不是万金油，不能抵挡所有垃圾评论。毕竟我没有广泛研究过评论机器人的工作原理，有可能人家就是使用自动化脚本模拟用户打开浏览器，输入网址然后填写评论，这也说不准。但是经过半个多月的试验，这个方法还算是比较靠谱的。至今没有见过一条机器人评论。有兴趣的朋友也可以试试。</p><p style="text-align: right;">——<a title="让博客不用Anti-Spam插件一样没有垃圾评论" href="http://www.imkevinyang.com/2010/02/%e8%ae%a9%e5%8d%9a%e5%ae%a2%e4%b8%8d%e7%94%a8Anti-Spam%e6%8f%92%e4%bb%b6%e4%b8%80%e6%a0%b7%e6%b2%a1%e6%9c%89%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba.html"><em><strong>Kevin Yang</strong></em></a></p>标签：<a href="http://www.imkevinyang.com/tags/antispam-plugin" title="AntiSpam plugin" rel="tag">AntiSpam plugin</a>, <a href="http://www.imkevinyang.com/tags/javascript" title="Javascript" rel="tag">Javascript</a>, <a href="http://www.imkevinyang.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a>, <a href="http://www.imkevinyang.com/tags/%e5%8d%9a%e5%ae%a2" title="博客" rel="tag">博客</a>, <a href="http://www.imkevinyang.com/tags/%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba" title="垃圾评论" rel="tag">垃圾评论</a>, <a href="http://www.imkevinyang.com/categories/techarticles/toolskills-techarticles" title="工具技巧" rel="tag">工具技巧</a>, <a href="http://www.imkevinyang.com/tags/%e8%a1%a8%e5%8d%95" title="表单" rel="tag">表单</a>, <a href="http://www.imkevinyang.com/tags/%e8%af%84%e8%ae%ba%e6%9c%ba%e5%99%a8%e4%ba%ba" title="评论机器人" rel="tag">评论机器人</a><br /><h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4><ul class="st-related-posts"><li><a href="http://www.imkevinyang.com/2009/11/button%e6%a0%87%e7%ad%be%e9%bc%a0%e6%a0%87%e7%82%b9%e5%87%bb%e4%ba%8b%e4%bb%b6%e7%9a%84%e8%a7%a6%e5%8f%91%e6%ba%90%e9%97%ae%e9%a2%98.html" title="Button标签鼠标点击事件的触发源问题 (2009/11/27)">Button标签鼠标点击事件的触发源问题</a> (2009/11/27)</li><li><a href="http://www.imkevinyang.com/2009/03/ie%e4%b8%ad%e4%bd%bf%e7%94%a8windowopen%e6%89%93%e5%bc%80%e6%96%b0%e7%aa%97%e5%8f%a3%e6%97%b6%e6%97%a0%e6%b3%95%e8%8e%b7%e5%8f%96referrer%e5%af%b9%e8%b1%a1.html" title="IE中使用window.open打开新窗口时无法获取Referrer对象 (2009/03/07)">IE中使用window.open打开新窗口时无法获取Referrer对象</a> (2009/03/07)</li><li><a href="http://www.imkevinyang.com/2010/07/javajs%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%8c%b9%e9%85%8d%e5%b5%8c%e5%a5%97html%e6%a0%87%e7%ad%be.html" title="Java/Js如何使用正则表达式匹配嵌套Html标签 (2010/07/30)">Java/Js如何使用正则表达式匹配嵌套Html标签</a> (2010/07/30)</li><li><a href="http://www.imkevinyang.com/2009/07/javascript-%e4%b8%ad%e7%9a%84false%e9%9b%b6%e5%80%bcnullundefined%e5%92%8c%e7%a9%ba%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%af%b9%e8%b1%a1.html" title="Javascript 中的false,零值,null,undefined和空字符串对象 (2009/07/07)">Javascript 中的false,零值,null,undefined和空字符串对象</a> (2009/07/07)</li><li><a href="http://www.imkevinyang.com/2009/05/javascript%e4%b8%ad%e8%8e%b7%e5%8f%96%e5%87%ba%e9%94%99%e4%bb%a3%e7%a0%81%e6%89%80%e5%9c%a8%e6%96%87%e4%bb%b6%e5%8f%8a%e8%a1%8c%e6%95%b0.html" title="Javascript中获取出错代码所在文件及行数 (2009/05/18)">Javascript中获取出错代码所在文件及行数</a> (2009/05/18)</li><li><a href="http://www.imkevinyang.com/2009/04/javascript%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%93%88%e5%b8%8c%e5%87%bd%e6%95%b0.html" title="Javascript字符串哈希函数 (2009/04/11)">Javascript字符串哈希函数</a> (2009/04/11)</li><li><a href="http://www.imkevinyang.com/2009/06/javascript%e6%93%8d%e7%ba%b5cookie.html" title="Javascript操纵Cookie (2009/06/11)">Javascript操纵Cookie</a> (2009/06/11)</li><li><a href="http://www.imkevinyang.com/2009/10/wordpress%e8%af%84%e8%ae%ba%e4%b8%ad%e4%bf%9d%e7%95%99html%e4%bb%a3%e7%a0%81.html" title="Wordpress评论中保留Html代码 (2009/10/31)">Wordpress评论中保留Html代码</a> (2009/10/31)</li><li><a href="http://www.imkevinyang.com/2009/08/%e4%b8%80%e5%8f%a5%e8%af%9d%e5%8d%9a%e5%ae%a22009-08-04.html" title="一句话博客2009-08-04 (2009/08/04)">一句话博客2009-08-04</a> (2009/08/04)</li><li><a href="http://www.imkevinyang.com/2010/05/%e4%b8%ba%e4%bb%80%e4%b9%88iis77-5%e7%9a%84gzip%e4%b8%8d%e8%b5%b7%e4%bd%9c%e7%94%a8.html" title="为什么IIS7/7.5的Gzip不起作用 (2010/05/08)">为什么IIS7/7.5的Gzip不起作用</a> (2010/05/08)</li></ul>]]></content:encoded> <wfw:commentRss>http://www.imkevinyang.com/2010/02/%e8%ae%a9%e5%8d%9a%e5%ae%a2%e4%b8%8d%e7%94%a8anti-spam%e6%8f%92%e4%bb%b6%e4%b8%80%e6%a0%b7%e6%b2%a1%e6%9c%89%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>