WordPress防止垃圾评论的,DIY验证码

跟目录 文件wp-comments-post.php
1、查找:
$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;

下面加:

//添加验证码 by:xiaohei QQ:77491010
if ( !$user->ID ) {
$a = ( isset($_POST['a']) ) ? trim($_POST['a']) : null;
$b = ( isset($_POST['b']) ) ? trim($_POST['b']) : null;
//$a = trim($_POST[a]);
//$b = trim($_POST[b]);
$sub = ( isset($_POST['sub']) ) ? trim($_POST['sub']) : null;
if((($a+$b)!=$sub)|| empty($sub)){
wp_die(__(‘You will calculate the numbers?’).$a.’+’.$b.’=’.$sub.’???’);
}
}
//添加验证码 by:xiaohei QQ:77491010 结束
—————————————————————————

2、文件wp-includes/comment-template.php

查找:

<?php echo $args['comment_notes_after']; ?>

下面加:

<?php //添加验证码 by:xiaohei QQ:77491010 $a=rand(0,10); $b=rand(10,20); ?>
You will calculate the numbers?
<span style=”color: #ff0000;”><?php echo $a;?>+<?php echo $b;?>=</span>
<input id=”sub” type=”text” name=”sub” maxlength=”2″ />
<input id=”a” type=”hidden” name=”a” value=”<?php echo $a;?>” />
<input id=”b” type=”hidden” name=”b” value=”<?php echo $b;?>” />
<?php //添加验证码 by:xiaohei QQ:77491010 结束?>

我用这样的方式来防止垃圾评论的,谢谢

WordPress防止垃圾评论的,DIY验证码》上有 4 条评论

  1. 感觉输入验证码不合适 如果ajax
    直接检测 评论地址 是不是默认是默认直接禁止掉 我那样就没垃圾评论了
    感觉缺点就是不支持js 就不能评论

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

You will calculate the numbers?     3+12=