背景

Typecho纯代码实现评论数学验证功能并且隐入评论框美化

6个月前 typecho帮助 23°C

直接上干货,首先是丢进主题里面的function里面

//算术验证评论
{
$comment = spam_protection_pre($comment, $post, $result);
}
function spam_protection_math(){
      $num1 = rand(1, 99);
    $num2 = rand(1, 99);
    echo "<div style=\"display:flex;align-items: center;\"><p for=\"math\" id=\"Verification_code\" style=\"margin-bottom:0\">  </p><input type=\"text\" name=\"sum\" class=\"text\" value=\"\" size=\"25\" id=\"sum\" tabindex=\"0\" style=\"flex:1\" placeholder=\" $num1+$num2= \"\">\n</div>";
    echo "<input type=\"hidden\" name=\"num1\" value=\"$num1\">\n";
    echo "<input type=\"hidden\" name=\"num2\" value=\"$num2\">";
}
function spam_protection_pre($comment, $post, $result) {
    if ($_REQUEST['text'] != null) {
        If($_POST['num1'] == null || $_POST['num2'] == null) {
            throw new Typecho_Widget_Exception(_t('验证码异常.', '评论失败'));
        } else {
            $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;
}

搜一下主题function里面是否存在themeInit的内容。如果有就直接用上面的,没的话
增加一行

function themeInit($comment)

然后下面的丢comments.php里面

<?php spam_protection_math();?> 

放那个位置?搜网址这些就能快速找到了
网址其实大多数根本用不到,还不如改成验证框,一般主题那些作者大佬都写了样式,所以直接干掉网址即可
效果见本站

Typecho纯代码实现评论数学验证功能并且隐入评论框美化

版权声明:小站所有内容均为互联网整理而来,仅供学习参考,如有侵犯您的版权,请联系删除。
本文链接:https://magicblue.cn/lost/14755.html
最后编辑: 23年04月02日

选择表情

网友评论

5个月前

所以说 这个主题官网挂了 应该在哪里买

6个月前

已经升1.2.1了

7个月前
头像 csp

抱抱

7个月前
头像 csp

有点惨啊

7个月前

支持支持一下