Stop SPAM with Akismet / php class


The class was developed in order to help the data process verification by using the Akismet service for detect SPAM. download now


After downloading the class, we add the class.akismet.php file. The follow is to create an instance of the class and assign parameters:

  • apikey: api key of Akismet
  • name: name of the user that send the form
  • email: email of the user that send the form
  • message: message to validate
  • type: form type (comment, trackback, pingback, registration)

Validating form:

In order to validate if the content of the form is SPAM, we would use the isSpam method, which respond true whenever the content is detected as SPAM; otherwise, it respond false.

Example:


<?php
require_once("class.akismet.php");

$akismet = new Akismet();
$akismet->apikey = "369ddb227ecb";
$akismet->name = "John Doe";
$akismet->email = "johndoe@example.com";
$akismet->message = "Hi, my name is John...";
if ($akismet->isSpam()) {
echo "SPAM!!!";
} else {
echo "Ok";
}
?>

Mark as SPAM

To report a message as SPAM you must use the submitSpam method.


<?php
require_once("class.akismet.php");

$akismet = new Akismet();
$akismet->apikey = "369ddb227ecb";
$akismet->name = "Viagra";
$akismet->email = "viagra@example.com";
$akismet->message = "Hello...";
$akismet->submitSpam();
?>

Uncheck Spam

To uncheck a message mark as SPAM you must use the submitHam method.


<?php
require_once("class.akismet.php");

$akismet = new Akismet();
$akismet->apikey = "369ddb227ecb";
$akismet->name = "Valid Friend";
$akismet->email = "friend-name@example.com";
$akismet->message = "Hello...";
$akismet->submitHam();
?>

Comments




 



Copyright © 2017 epictrim. All rights reserved.What we doOur WorkInsideIdeasJoin UsContact Us