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:
-
$WordPressAPIKey = 'aoeu1aoue';
-
$MyBlogURL = 'http://www.example.com/blog/';
-
-
$akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
-
$akismet->setCommentAuthor($name);
-
$akismet->setCommentAuthorEmail($email);
-
$akismet->setCommentAuthorURL($url);
-
$akismet->setCommentContent($comment);
-
$akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
-
-
if($akismet->isCommentSpam())
-
// store the comment but mark it as spam (in case of a mis-diagnosis)
-
else
-
// 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:
-
$akismet->submitSpam();
and
-
$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: 86% [?]
September 23rd, 2009 - 08:12
Work grate ! Thank YOU !
October 7th, 2009 - 07:56
Thanks for the code. It’ll make my life easier.
October 23rd, 2009 - 11:56
Thanks for this nice little class. I just came across it in my search for something to battle contact-form spam
One note, as I was looking for a TypePad-class, I ran across a minor style-issue: line 181
$this->wordPressAPIKey . ‘.rest.akismet.com’
should be:
$this->wordPressAPIKey . ‘.’ . $this->akismetServer
December 4th, 2009 - 04:21
This is really great thank you.
January 13th, 2010 - 17:57
Is there any way at all of incorporating this into a phpBB forum? I get loads of spammers trying to register and leave spam posts – Akismet stops them DEAD on my blog!
January 13th, 2010 - 17:59
Is there any way of incorporating this script into a phpBB forum running on MySQL and PHP5? I love Akismet on my blog and would love to have it on my forum as well if possible!
January 15th, 2010 - 20:42
@Bruce
There is a module for Akismet for phpBB:
http://www.phpbb.com/community/viewtopic.php?f=70&t=1340275
January 15th, 2010 - 22:01
Seems to no longer work, perhaps Akismet changed their API.
January 16th, 2010 - 23:48
Thanks for this script, but it looks like it no longer works.
I will check to be sure Akismat have not changed their API.
Thanks again.
January 22nd, 2010 - 15:28
You can use http 1.1 if you add “Connection: close” in the http request header.
February 4th, 2010 - 09:25
Same problem here …
Can`t find any API changes on the akismet page, so I can`t fix it myself … Any ideas?
February 10th, 2010 - 16:28
I use your module on two web sites that I maintain and using your module has helped reduce the amount of spam comments that get posted to the web site by a very large amount.
I just thought that I’d stop by your web site and say thanks for all your work on this very helpful module.
February 12th, 2010 - 07:17
Found the problem, documented it on my blog here: http://www.chuggnutt.com/2010/02/11/akismet-changed-their-return-values.php. Hope this helps!
April 25th, 2010 - 08:47
Just installed this on my (dutch) website
great job. I hope it works
(only problem is the guestbook actually xD)
May 5th, 2010 - 01:33
Awesome
Many thanks!
June 9th, 2010 - 10:09
Great in just used in my guestbook web. That is actualy works! thanks
June 13th, 2010 - 19:27
Brilliant! I am going to use it to make a CakePHP Component