Code _php tips for using Akismet to prevent spam comments in PHP

Source: Internet
Author: User
However, no one is perfect, plug in (pieces) without finishing! Akismet is not perfect, recently, I often in the Akismet judge for rubbish message to find "good people" message, however, sometimes a long time automatically deleted, loss of precious friendship and messages.
Don't forget to modify the __your_akismet_key__ in the code, __your_website_url__ and __your_name__
http://www.script-tutorials.com/akismet-spam-protection/
index.php
Copy Code code 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= " "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.