Php uses Akismet to prevent spam comments. However, no one is perfect, and no plug (pieces) is complete! Akismet is not perfect either. Recently, I often find a "good guy" message in the comment that Akismet judges as spam. However, it is deleted automatically after a long time, loss of valuable friendship and messages.
Do not 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
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'
';
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;
}
?>