php中使用Akismet防止垃圾评论的代码


Posted in PHP onJune 10, 2011

然而,人无完人,插(件)无完插!Akismet也并非完美,最近, 我常在被Akismet评判为垃圾的留言中找到“好人”的留言,然而,有时时间长了就自动删除了,损失珍贵的友情和留言。
别忘了修改代码中的 __YOUR_AKISMET_KEY__, __YOUR_WEBSITE_URL__ and __YOUR_NAME__
http://www.script-tutorials.com/akismet-spam-protection/
index.php

<? 
require_once ('classes/Akismet.class.php'); 
class MySpamProtection { 
// variables 
var $sMyAkismetKey; 
var $sWebsiteUrl; 
var $sAuthName; 
var $sAuthEml; 
var $sAuthUrl; 
var $oAkismet; 
// constructor 
public function MySpamProtection() { 
// set necessary values for variables 
$this->sMyAkismetKey = '__YOUR_AKISMET_KEY__'; 
$this->sWebsiteUrl = '__YOUR_WEBSITE_URL__'; 
$this->sAuthName = '__YOUR_NAME__'; 
$this->sAuthEml = ''; 
$this->sAuthUrl = ''; 
// Akismet initialization 
$this->oAkismet = new Akismet($this->sWebsiteUrl ,$this->sMyAkismetKey); 
$this->oAkismet->setCommentAuthor($this->sAuthName); 
$this->oAkismet->setCommentAuthorEmail($this->sAuthEml); 
$this->oAkismet->setCommentAuthorURL($this->sAuthUrl); 
} 
public function isSpam($s) { 
if (! $this->oAkismet) return false; 
$this->oAkismet->setCommentContent($s); 
return $this->oAkismet->isCommentSpam(); 
} 
} 
echo <<<EOF 
<style type="text/css"> 
form div { 
margin:10px; 
} 
form label { 
width:90px; 
float:left; 
display:block; 
} 
</style> 
<form action="" method="post"> 
<div><label for="author">Author</label><input id="author" name="author" type="text" value="" /></div> 
<div><label for="comment">Comment</label><textarea id="comment" name="comment" cols="20" rows="4"></textarea></div> 
<div><input name="submit" type="submit" value="Send" /></div> 
</form> 
EOF; 
if ($_POST) { 
// draw debug information 
echo '<pre>'; 
print_r($_POST); 
echo '</pre>'; 
// obtain sent info 
$sPostAuthor = $_POST['author']; 
$sCommentComment = $_POST['comment']; 
// check for spam 
$oMySpamProtection = new MySpamProtection(); 
$sAuthorCheck = ($oMySpamProtection->isSpam($sPostAuthor)) ? ' "Author" marked as Spam' : '"Author" not marked as Spam'; 
$sCommentCheck = ($oMySpamProtection->isSpam($sCommentComment)) ? ' "Comment" marked as Spam' : '"Comment" not marked as Spam'; 
echo $sAuthorCheck . '<br />' . $sCommentCheck; 
} 
?>

source.zip

PHP 相关文章推荐
用libtemplate实现静态网页生成
Oct 09 PHP
MySQL中create table语句的基本语法是
Jan 15 PHP
PHP投票系统防刷票判断流程分析
Feb 04 PHP
PHP中数字检测is_numeric与ctype_digit的区别介绍
Oct 04 PHP
PHP采集类snoopy详细介绍(snoopy使用教程)
Jun 19 PHP
php连接odbc数据源并保存与查询数据的方法
Dec 24 PHP
PHP生成压缩文件实例
Feb 07 PHP
PHP在线打包下载功能示例
Oct 15 PHP
PHP基于curl实现模拟微信浏览器打开微信链接的方法示例
Feb 15 PHP
docker-compose部署php项目实例详解
Jul 30 PHP
php swoole多进程/多线程用法示例【基于php7nts版】
Aug 12 PHP
php设计模式之职责链模式实例分析【星际争霸游戏案例】
Mar 27 PHP
php中通过虚代理实现延迟加载的实现代码
Jun 10 #PHP
php获取后台Job管理的实现代码
Jun 10 #PHP
php下通过curl抓取yahoo boss 搜索结果的实现代码
Jun 10 #PHP
PHP缩略图等比例无损压缩,可填充空白区域补充色
Jun 10 #PHP
PHP网站备份程序代码分享
Jun 10 #PHP
php在页面中调用fckeditor编辑器的方法
Jun 10 #PHP
PHP中遍历stdclass object的实现代码
Jun 09 #PHP
You might like
php stream_get_meta_data返回值
2013/09/29 PHP
PHP反射使用实例和PHP反射API的中文说明
2014/07/02 PHP
Laravel框架用户登陆身份验证实现方法详解
2017/09/14 PHP
用js实现的自定义的对话框的实现代码
2010/03/21 Javascript
jquery实现类似淘宝星星评分功能实例
2014/09/12 Javascript
javascript常用函数归纳整理
2014/10/31 Javascript
JSON取值前判断
2014/12/23 Javascript
JS使用ajax从xml文件动态获取数据显示的方法
2015/03/24 Javascript
鼠标经过子元素触发mouseout,mouseover事件的解决方案
2015/07/26 Javascript
javascript实现无缝上下滚动特效
2015/12/16 Javascript
在 Node.js 中使用原生 ES 模块方法解析
2017/09/19 Javascript
mac上配置Android环境变量的方法
2018/07/08 Javascript
VUE实现移动端列表筛选功能
2019/08/23 Javascript
vue的滚动条插件实现代码
2019/09/07 Javascript
react实现移动端下拉菜单的示例代码
2020/01/16 Javascript
简单了解three.js 着色器材质
2020/08/03 Javascript
小程序组件传值和引入sass的方法(使用vant Weapp组件库)
2020/11/24 Javascript
[45:44]完美世界DOTA2联赛PWL S2 FTD vs PXG 第一场 11.27
2020/12/01 DOTA
python动态加载变量示例分享
2014/02/17 Python
Mac中升级Python2.7到Python3.5步骤详解
2017/04/27 Python
Python基于列表模拟堆栈和队列功能示例
2018/01/05 Python
手把手教你用python抢票回家过年(代码简单)
2018/01/21 Python
python实现五子棋人机对战游戏
2020/03/25 Python
Python利用WMI实现ping命令的例子
2019/08/14 Python
详解Python list和numpy array的存储和读取方法
2019/11/06 Python
Python无头爬虫下载文件的实现
2020/04/02 Python
Python实现Keras搭建神经网络训练分类模型教程
2020/06/12 Python
基于Pytorch版yolov5的滑块验证码破解思路详解
2021/02/25 Python
澳大利亚拥有最佳跳伞降落点和最好服务的跳伞项目运营商:Skydive Australia
2018/03/05 全球购物
教职工代表大会主持词
2014/04/01 职场文书
高考励志标语
2014/06/05 职场文书
学校四群教育实施方案
2014/06/12 职场文书
新闻通讯稿范文
2015/07/22 职场文书
2016年过年放假安排通知
2015/08/18 职场文书
redis连接被拒绝的解决方案
2021/04/12 Redis
python基础之类属性和实例属性
2021/10/24 Python