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

然而,人无完人,插(件)无完插!Akismet也并非完美,最近, 我常在被Akismet评判为垃圾的留言中找到“好人”的留言,然而,有时时间长了就自动删除了,损失珍贵的友情和留言。
别忘了修改代码中的 YOUR_AKISMET_KEY,YOUR_WEBSITE_URL and YOUR_NAME
http://www.script-tutorials.com/akismet-spam-protection/
index.PHP
<div class="codetitle"><a style="CURSOR: pointer" data="77256" class="copybut" id="copybut77256" onclick="doCopy('code77256')"> 代码如下:

<div class="codebody" id="code77256">
<?
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;
}

<form action="" method="post">
<label for="author">Author

<label for="comment">Comment<textarea id="comment" name="comment" cols="20" rows="4">



EOF;
if ($_POST) {
// draw debug information
echo '
'; 
print_r($_POST);
echo '
';
// 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 . '
' . $sCommentCheck;
}
?>
source.zip

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...