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

然而,人无完人,插(件)无完插!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 <<

form div {

margin:10px;

}

form label {

width:90px;

float:left;

display:block;

}

Author
Comment

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值