However, no one is perfect, and no plug-in 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
Copy codeThe 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
<Style type = "text/css">
Form div {
Margin: 10px;
}
Form label {
Width: 90px;
Float: left;
Display: block;
}
</Style>
<Form action = "" method = "post">
<Div> <label for = "author"> Author </label> <input id = "author" name = "author" type = "text" value = ""/> </div>
<Div> <label for = "comment"> Comment </label> <textarea id = "comment" name = "comment" cols = "20" rows = "4"> </textarea> </div>
<Div> <input name = "submit" type = "submit" value = "Send"/> </div>
</Form>
EOF;
If ($ _ POST ){
// Draw debug information
Echo '<pre> ';
Print_r ($ _ POST );
Echo '</pre> ';
// 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. '<br/>'. $ sCommentCheck;
}
?>
Source.zip