Use akismet in PHP to prevent spam comments

Source: Internet
Author: User

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.
Don't forget to modify Code _ Your_akismet_key __, _ your_website_url _ and _ your_name __
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
<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

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.