Typecho的垃圾批评照样比较多的,除了插件外,还能够经由过程PHP函数完成简朴的算术验证码。
第一步function.php以下函数
function themeInit($comment){$comment = spam_protection_pre($comment, $post, $result);}function spam_protection_math(){ $num1=rand(1,49); $num2=rand(1,49); echo "<label for=\"math\">请输入<code>$num1</code>+<code>$num2</code>的计算结果:</label>\n"; echo "<input type=\"text\" name=\"sum\" class=\"text\" value=\"\" size=\"25\" tabindex=\"4\" style=\"width:218px\" placeholder=\"计算结果:\">\n"; echo "<input type=\"hidden\" name=\"num1\" value=\"$num1\">\n"; echo "<input type=\"hidden\" name=\"num2\" value=\"$num2\">";}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('对不起: 请输入验证码。<a href="javascript:history.back(-1)">返回上一页</a>','批评失利')); break; default: throw new Typecho_Widget_Exception(_t('对不起: 验证码毛病,请<a href="javascript:history.back(-1)">返回</a>重试。','批评失利')); } return $comment;}第二步comments.php增加函数
翻开主题comments.php文件,在恰当为止插进去以下代码:
<?php spam_protection_math();?>假如以为100之内太难了,请修复function.php中增加的代码中rand背面的数字局限。
文章转自:https://minirizhi.com/22.html

评论列表