Code to use Akismet to prevent spam comments in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:28:55
Original
989 people have browsed it

However, no one is perfect, and no one is perfect! Akismet is not perfect. Recently, I often find messages from "good people" among the messages that Akismet has judged as spam. However, sometimes they are automatically deleted after a long time, resulting in the loss of precious friendships and messages.
Don’t forget to modify __YOUR_AKISMET_KEY__, __YOUR_WEBSITE_URL__ and __YOUR_NAME__ in the code
http://www.script-tutorials.com/akismet-spam-protection/
index.php

Copy code The code is as follows:

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;
if ($_POST) {
// draw debug information
echo '
'; <br>print_r($_POST); <br>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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323533.htmlTechArticleHowever, no one is perfect, and no one is perfect! Akismet is not perfect. Recently, I often find messages from "good people" among the messages that Akismet judges as spam. However, sometimes it takes a long time...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!