Use Akismet to prevent spam comments-PHP source code

Source: Internet
Author: User
Using Akismet to prevent Spam comments Akismet is an excellent plug-in that prevents Spam messages. most wordpress blogger is using it. with akismet, there is basically no need to worry about Spam messages. 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 __

 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 <<
 
  form p {margin:10px;}form label {width:90px;float:left;display:block;}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;}?>

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.