我们有在使用Typecho程序的时候会发现,这款程序确实简单易用但是有些功能也是被精简的。比如ZBLOG PHP他是自带可以开启验证码功能的,而Typecho需要评论验证码功能则需要单独安装插件或者用代码实现。这里老蒋找到一个网上一个网友的办法,是通过添加简单的算术运算,然后提高反垃圾功能。
第一、代码部分

//算术验证评论
function themeInit($comment){
$comment = spam_protection_pre($comment, $post, $result);
}
function spam_protection_math(){
    $num1=rand(1,49);
    $num2=rand(1,49);
    echo "\n";
    echo "\n";
    echo "\n";
    echo "";
}
function spam_protection_pre($comment, $post, $result){
    $sum=$_POST['sum'];
    switch($sum){
        case $_POST['num1']+$_POST['num2']:
        break;
        case null:
        throw new Typecho_Widget_Exception(_t('对不起: 请输入验证码。返回上一页','评论失败'));
        break;
        default:
        throw new Typecho_Widget_Exception(_t('对不起: 验证码错误,请返回重试。','评论失败'));
    }
    return $comment;
}

添加到我们当前主题的Functions.php。
第二、添加位置


在comments.php合适的位置加上代码就可以。
本文参考:https://minirizhi.com/22.html