Code for preventing spam comments using Akismet in php _ PHP Tutorial

Source: Internet
Author: User
Use Akismet in php to prevent spam comments. However, no one is perfect, and no plug-in is complete! Akismet is not perfect either. Recently, I often find a "good man" message in the comment that Akismet judges as spam) no end plug! 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;
}
?>



Source.zip

There is no plug-in for the parts! Akismet is not perfect either. Recently, I often find "good guys" in the comments that Akismet judges as spam. However, it sometimes takes a long time...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.