PHP5 Akismet

Introduction

This is a simple little PHP5 class that enables you use the Akismet anti-spam service in your PHP5 application.

Download

Both versions are the same and require PHP5.

Installation

Untar or unzip the archive and put the Akismet.class.php file somewhere accessible to your scripts. Use include or a derivative to import it into your script.

Usage

Before you can use Akismet, you need a WordPress API key (they are free and getting one takes about five minutes). Once you have one, take a look at the code below:

  1. $WordPressAPIKey = ‘aoeu1aoue’;
  2. $MyBlogURL = ‘http://www.example.com/blog/’;
  3.  
  4. $akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
  5. $akismet->setCommentAuthor($name);
  6. $akismet->setCommentAuthorEmail($email);
  7. $akismet->setCommentAuthorURL($url);
  8. $akismet->setCommentContent($comment);
  9. $akismet->setPermalink(‘http://www.example.com/blog/alex/someurl/’);
  10.  
  11. if($akismet->isCommentSpam())
  12.   // store the comment but mark it as spam (in case of a mis-diagnosis)
  13. else
  14.   // store the comment normally

That’s just about it. In the event that the filter wrongly tags messages, you can at a later date create a new object and populate it from your database, overriding fields where necessary and then use the following two methods to train it:

  1. $akismet->submitSpam();

and

  1. $akismet->submitHam();

to submit mis-diagnosed spam and ham, which improves the system for everybody. See the included documentation for a complete run-down of all available methods.

Changelog

Version 0.4

  • Performance – changed HTTP version from 1.1 to 1.0 (with thanks to Jan De Poorter).
  • Performance – No longer issues a separate HTTP request to check validity of the API key with every instantiation.
  • Added a new public method ‘isKeyValid’ to manually check validity of the API key passed to the constructor.
  • The method ‘isCommentSpam’ (rather than the constructor) will now throw an exception if the API key is invalid.
  • Tidied up internal structure a bit.

Version 0.3

Internal testing version

Version 0.2

Initial release

Version 0.1

Internal testing version

Popularity: 100% [?]

0 Responses to “PHP5 Akismet”


  • No Comments

Leave a Reply