用 CSS 武器阻击垃圾留言! 16

  哦也,当我看到原文的标题时,我就忍不住点击 blog it 发布到煎蛋来了。真的是很棒的教程!作者说,自从用了这招,垃圾留言狂跌到 0 个。

  我们先来看招:

  下面是简单的 HTMl 代码:

<form method="post" action="process.php">  
<fieldset>
  <label>Name: </label><input name="name" type="text" /><br />
  <label>Email: </label><input name="email" type="text" /><br />
  <label>Comment: </label><input name="comments" type="text" /> <input name="info" class="special" type="text" />
  <input value="Send" type="submit" />  
</fieldset>
</form>

  这段代码的关键是:在显示 Comment 的地方有两个输入框,第一个(info 输入框)是给专门制造垃圾留言的爬虫(Spammer)用的,第二个是给人类用的。
# Copyright for Jandan.net(http://jandan.net/)
  CSS 代码:

body {
line-height:35px;
font-family:Arial, Helvetica, sans-serif;
color:#333;
font-size:14px;
}
.special {
width:5px;
visibility:hidden;
}

  body 部分很普通,关键是 .special ,info 输入框就是调用了这个样式。因为 info 输入框的宽度只有 5 像素,而且它不可见,就是说它无法显示在网页上,所以我们人眼看不到。而Spammer可就没长眼睛啰,它们会以为这里是要填写的。

  所以,我们只需要在 process.php (当然也可以是其他语言编写的)里,这样处理:只要 info 输入框里面有数据的话(是人就不会在 info 里输入东西的,哈哈,因为我们看不见它。),数据就不会写进数据库。

  当然道高一尺,魔高一丈。这个小技巧也是很容易破解。不过,有招总比没招好。大家可以在这里看到测试页面,该测试页面也给出了 process.php 的处理代码。我想,没有人会喜欢那些乱七八糟的验证码。

来源 | 链接

# 本文来自煎蛋(http://jandan.net/),作者为sfufoet(遵循 CC,如转载请保留此声明)


blogmarks del.icio.us Google Live MisterWong Reddit Technorati TwitThis QQ 垦一垦

关于 “用 CSS 武器阻击垃圾留言!”有 16 篇评论

  1. 1 fires 说 : Reply to this comment
    2007-06-27 10:18 am

    我只想跳出大喊一声,沙发

  2. 2 耗子小三 说 : Reply to this comment
    2007-06-27 10:21 am

    我只想跳出来对一楼大喊一声:不许动!!!

  3. 3 sein 说 : Reply to this comment
    2007-06-27 10:22 am

    这个想法太有才了

  4. 4 火星人 说 : Reply to this comment
    2007-06-27 10:33 am

    的确比较巧妙,但是绕过也很容易

  5. 5 sfufoet 说 : Reply to this comment
    2007-06-27 10:37 am

    这个只能用来对付一部分 Stupid Spammer 。

  6. 6 longinus 说 : Reply to this comment
    2007-06-27 4:04 pm

    厉害厉害,不得不服。

  7. 7 黑星星 说 : Reply to this comment
    2007-06-27 4:40 pm

    什么人想出了这么NB的办法啊

  8. 8 IwfWcf 说 : Reply to this comment
    2007-06-27 5:35 pm

    这个方法还有违反搜索引擎规定的嫌疑吧?

  9. 9 vampire 说 : Reply to this comment
    2007-06-27 5:50 pm

    聪明啊~

  10. 10 TJ 说 : Reply to this comment
    2007-06-28 9:32 am

    我想试试

  11. 11 islet8 说 : Reply to this comment
    2007-06-28 9:38 am

    这个办法能解决垃圾trackback么?我在wp里感觉垃圾tb比垃圾留言多多了

  12. 12 leavic 说 : Reply to this comment
    2007-06-28 11:05 am

    麻烦讲讲process.php的修改,这才是关键

  13. 13 tobe 说 : Reply to this comment
    2007-06-28 11:08 am

    @leavic 测试页面那个链接里面有

  14. 14 火星人feuvan 说 : Reply to this comment
    2007-06-29 2:29 pm

    11楼的
    Trackback Validator

  15. 15 华华 说 : Reply to this comment
    2007-08-16 5:38 pm

    为防止搜索引擎 XX
    不要 visibility:hidden;
    直接让绝对定位到屏幕外好了

  16. 16 網頁設計 说 : Reply to this comment
    2007-10-01 10:41 am

    哈哈~很妙,蠻有用的

想说点什么呢...

XHTML: You can use these tags: <a href="" title=""> <img src="" alt=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>