New Akismet Class
Jan 13, 2007
Overview
The people over at Akismet have created a wonderful API that offers bloggers (with an API key) an effective way to filter comment spam that may flood their sites. My last Akismet class was a quick rewrite of the original PHP5 class provided, but this new class overcomes some problems with error-handling and uses a much cleaner method of submitting your comment data to Akismet.Download
Updated January 7, 2008Update Announcement
January 7, 2008
The constructor's $comment parameter is now optional. The methods Akismet::getComment() and Akismet::setComment($comment) have been added. These modifications allow the class to handle multiple comments per object instantiation. Repeatedly use setComment($comment) then isSpam() to check several comments without having to create a new Akismet object every time.Usage
Please visit the documentation page for examples of usage and error-handling.I'd like to thank OldGuy for working with me on testing and debugging this new Akismet class and for writing the new documentation page.
39 commentsBret Kuhns
Jan 22, 2007
Dustin, I'm glad you like the changes. Please let me know if you run into any troubles with the class so I can take care of any bugs.
Sasha
Jan 24, 2007
I'm loving how easy your class is to use - I was able to implement it in no time! However, I was wondering, can I also use your class to submit false positives and negatives to Akismet? Like they say on their website, Akismet will only get smarter if we train it and let it know when it was wrong. ;)
Bret Kuhns
Jan 24, 2007
Sasha, I'm hoping on improving the documentation of the class in the future, but the Akismet::submitHam() Akismet::submitSpam() methods are available to notify Akismet of false positives or negatives.
dusoft
Jan 25, 2007
You should add _ (underline to function calls of submitSpam and submitHam, otherwise functions are not defined... thanks for the class.
is your MIT license compatible with GPL?
Bret Kuhns
Jan 26, 2007
dusoft, the underline issue has already been taken care of (the ZIP download reflects this). The MIT license is less restrictive than GPL, it is almost as if you had written the code yourself (just keep the copyright notice in the class). You are completely free to use and/or modify this code for any "home" or business use.
Nicholas Moline
Jan 26, 2007
Great work on the new version of the class, the error catching makes a real difference, but I have one question, there's a print_r in the constructor function, echoing out the contents of the array, is there a reason this is necessary, or was it used during development and not removed when posted here on the site?
Bret Kuhns
Jan 26, 2007
Nicholas, that's exactly what happened. I forgot to take out that line before uploading it, thank you for pointing it out! That has now been taken care of. My apologies.
Gregg Kemp
Mar 6, 2007
Is there a way to display the number of spam blocked by Akismet through your class, or otherwise?
Bret Kuhns
Mar 8, 2007
Gregg, this is something that your system would need to implement on its own. My class is just a tool. In order to do what you're asking, you would need to increment a value stored inside either a file or database table every time my class finds a spam comment. You would do this when checking the comment via the isSpam() method (if is spam, then increment spam count). I hope that helps.
Gregg Kemp
Mar 16, 2007
gotcha. thanks.
Garrett
Mar 18, 2007
I'm sorry, I hate to sound like a newb but Iam fairly new to php. I've read that article as well as many others.
I only have a few questions.
Where exactly do you add the "include" in your script?
More than that, would anyone like to help a (very) young programmer with a little guide? If it doesn't take to much time of course.
Thanks
Daniel15
Mar 20, 2007
Awesome, I wish I would have found this earlier :P
I used your old class in my SMF Akismet mod (http://www.dansoftaustralia.net/products/smf-mods/akismet.htm), and I needed to edit bits of the code to add some error handling (I admit, my edits were quite ugly). This new class will make it a lot easier for me :D
Thanks! :)
Roland Haeder
Apr 8, 2007
Easy to use class! Nice work. :) I have included it in my patch for the Gbook-MX guestbook script: http://gbook.mxchange.org Just in case if you want to check it out... ;-)
David
May 21, 2007
hmmm... looks like just what I needed for my new blog system. - I'll let you know when I finish it. ;)
Paul
Jun 5, 2007
Great tool, thank you for doing this. I'm getting an error though (and not sure what it means or how to fix it):
Fatal error: Cannot instantiate non-existent class: akismet in /home/armstron/public_html/functions/functions.php on line 1682
its referring to this :
$akismet = new akismet("http://armstrongcircus.com/", "my wordpress api key -- which i have but am not obviously going to put it here", $comment);
thanks for any help you can give.
Bret Kuhns
Jun 5, 2007
Paul, you're getting this error because you are trying to instantiate the class before it exists. You need to require/include the akismet.class.php file *before* creating a new akismet() object.
Felix Manea
Jun 14, 2007
I have been playing around with this class and it works great as a client... but I am having trouble with their server... it does not return correct answers, it marks either all as spam, or all as not spam. Have anyone else encountered this problem?
Matti Mattila
Jun 27, 2007
I hooked this class into my very own blogging software and it works great! Thanks!
DjSlash
Jul 2, 2007
Great work, I have implented it in several modules and sites now. Your documentation is very clear and easy to use. I think I'll be using it many times more. :)
Joost
Jul 13, 2007
I'm wondering how I can check to see if it's working. If i fill out a comment field with stuff like "viagra cheap cheap sex incr34se ur pen1s s1z3" (hope akismet won't think i'm a spammer now) than I still get approval for the comment. Is this because Akismet doesn't have my IP address listed as spammer?
Or, in a rewrite my question also is: how can I trigger akismet to think something is spam?
Bret Kuhns
Jul 13, 2007
Joost, Akismet is not counting your comments as spam because it looks into more than just the comment's body to consider spam. To test for a spam comment, use "viagra-test-123" as the author name and it should get flagged by Akismet.
Custom PHP MySql Programming
Jul 18, 2007
Spam is always a concern Thanks for your help
Chris
Aug 9, 2007
Glad to know tools like this are out there. One quick question though, how do I see the spam that akismet has filtered using this class? I can't seem to find that feature on wordpress.
Bret Kuhns
Aug 13, 2007
Chris, I've never used Wordpress before so I really have no idea how to get what you're looking for. You might want to check out the Wordpress forums (if they exist?) on help in that area. My Akismet class is intended for custom made blog systems outside of Wordpress.
Kevin
Aug 17, 2007
Thanks for the update on the class, awesome work!
Michael Buckley
Sep 2, 2007
Very good php class, I managed to add this into my own news script that I wrote a while ago in less then half an hour.
sohbet odalari
Sep 4, 2007
thank you
Cyrille
Nov 7, 2007
Thank you for this class!
josefk
Nov 30, 2007
Further to Joost's comment above, it seems that a obvious spam comment is not enough for akismet to flag the comment as spam. It needs an 'author'? Not all my forms have author and email fields... so, great for when these fields are present, pretty awful when only submitting a spam comment...
Bret Kuhns
Dec 3, 2007
@Kevin/Michael/sohbet/cyrille: I'm glad it could be of use!
@josefk: The author field is only used to trigger a test-only flag in Akismet itself. You can still use Akismet on submissions that don't an author, but other information is still used about how the user submitted the comment that is used in addition to the comment's own content to determine if it is spam or not.
@josefk: The author field is only used to trigger a test-only flag in Akismet itself. You can still use Akismet on submissions that don't an author, but other information is still used about how the user submitted the comment that is used in addition to the comment's own content to determine if it is spam or not.
Ryan
Feb 7, 2008
Great class, cheers! I'm loving how easy it was to implement and how well it works. If only Akisment would block those annoying "highrelevantsearch.com" posts. Anyone else getting peppered with these?
Quảng Bá Website
Feb 21, 2008
Well! done and very easy to set up. Thanks!
Colin
Mar 2, 2008
Hey dude - great class, although I'm having some problems with it/ Akismet.
Basically the request to Akismet occasionally takes ages. Unfortunately the request times out... could you add a feature to allow a timeout to be set?
Pär
Mar 4, 2008
I also had some problems with timeouts. Changes from HTTP 1.1 to HTTP 1.0 seems to have solved it. Read more here:
http://blog.defv.be/2008/2/22/akismet-problems
Kevin
Apr 5, 2008
Thanks a lot for this super-easy-to-use class, I like it a lot. It took me only a couple of minutes to make it work with my "Comments Extension" for the BIGACE CMS: http://www.bigace.de/
Thank you very much! Free software is just the best :-D
Bob Goyetche
Apr 10, 2008
Awesome! in and running in 5 mins. Thanks!
Jamie Thompson
May 13, 2008
Thought i'd share my experience with using this class on a high traffic site. We were getting delays of 30-45 seconds every time a comment was submitted. HTTP 1.1 turned out to be the culprit.
By forcing the class to use HTTP 1.0 simply by editing line 141 the problem was immediately solved.
If you're noticing speed issues with Askismet then you'll probably find that HTTP 1.1 is the problem
Cent
Jun 12, 2008
I read something that referred to: "HTTP/1.0 does not support persistent connections so the problem is also fixed when you switch to HTTP/1.0.".
Is there any inherent value in using HTTP/1.1 vs 1.0? As my integration was suffering from PHP timing out or hitting 30-60 seconds limits, I switched to 1.0 which fixed the problem as people have shared.
So my question is to switch back to 1.1, how would I close the connection? I read "Specifying a 'Connection: close' header will fix the problem." Maybe I'm unclear exactly how to do that.






Dustin Noe