记录Typecho纯代码算术验证
2022-12-26
分类: typecho
简介: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后面的数字范围。
typecho评论验证码插件
2022-12-24
分类: typecho
简介:很多用户受到垃圾评论的困扰,因为某些国内服务器无法连接到Akismet服务,所以垃圾评论肆虐。有的用户即使启用了Akismet插件,但成千上万条垃圾评论对服务器负载也造成了影响。因此我开发了一个验证码插件,有需要开发类似插件的用户也可以借鉴一下开发方法。使用方法很简单,下载插件解压后,将其上传至/usr/plugins/目录下,先在后台启用插件,然后编辑摸板,在评论的表单位置也就是comments的form标签之间的任何你认为合适的地方,加上如下代码<p><?php Captcha_Plugin::output(); ?></p>[hide]评论验证码插件.zip[/hide]
非插件实现Emlog内容页判断百度收录与否
2021-01-24
分类: Emlog
简介:本方法有插件实现,本教程由独狼移植四少爷博客制作的插件,这样就不用开启插件就可以使用了,经过测试正常方才发布,只为收集EMLOG教程,让更多的网友受益。不废话了,下面进入正题,首先将以下代码存放在模板目录的module文件中: <?php //判断内容页是否百度收录 function baidu($url){ $url='http://www.baidu.com/s?wd='.$url; $curl=curl_init();curl_setopt($curl,CURLOPT_URL,$url);curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);$rs=curl_exec($curl);curl_close($curl);if(!strpos($rs,'没有找到')){return 1;}else{return 0;}} function logurl($id){$url=str_replace(array('http://'),'',Url::log($id)); if(baidu($url)==1){echo "百度已收录"; }else{echo "<a style=\"color:red;\" rel=\"external nofollow\" title=\"点击提交收录!\" target=\"_blank\" href=\"http://zhanzhang.baidu.com/sitesubmit/index?sitename=$url\">百度未收录</a>";}} ?>在模板的echo_log.php文件中调用<?php echo logurl($logid);?>即可