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

yipeiwu_com5年前PHP代码库
然而,人无完人,插(件)无完插!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 无限分类三种方式 非函数的递归调用!

PHP 无限分类三种方式 非函数的递归调用!

php无限分类大致有三种方式,   1、数据库通过设置父类ID来进行唯一索引,然后使用函数的递归调用实现无限分类;   2、数据库设计通过特定格式进行排列,然后使用mysql查询关键函数...

php中使用url传递数组的方法

本文实例讲述了php中使用url传递数组的方法。分享给大家供大家参考。具体分析如下: 数组传递这么写: 复制代码 代码如下:echo"<a href=2.php?info=...

php 常用算法和时间复杂度

按数量级递增排列,常见的时间复杂度有:常数阶O(1),对数阶O(log2n),线性阶O(n),线性对数阶O(nlog2n),平方阶O(n2),立方阶O(n3)复制代码 代码如下://二分...

php自动识别文字编码并转换为目标编码的方法

本文实例讲述了php自动识别文字编码并转换为目标编码的方法。分享给大家供大家参考。具体如下: 在PHP处理页面的时候,我们对于字符集的转换都是采用了iconv或者mb_convert等函...

PHP校验ISBN码的函数代码

详细资料可以参考:国际标准书号 – 维基百科,下面还是简述一下什么是ISBN码: 国际标准书号(International Standard Book Number,ISBN;拟发音is...