Like many blogs out there, I have spam-checking service Akismet set up to filter out the comment spam. It’s built-in on my Brew Site WordPress blog, but on chuggnutt and Hack Bend it’s using a PHP class that I coded myself.
Up until a few days ago, it’s been working beautifully on my two non-WordPress blogs. But all of a sudden, every spam comment to the two blogs started coming through approved (not marked as spam). Every single one.
Tonight I started poking around my code and the Akismet API to see if anything had changed. According to their API documentation, Akismet should only return two possible values for the spam check: "true" or "false".
I poked around with some cURL tests but that was inconclusive; appropriate testing strings ("viagra-test-123" will always return true) were performing as specified. But when I entered that test string as a comment on my site, it was not flagged as spam. Clearly, something had changed with the API, since the code has been running along just fine since, what, 2006?
So I set my PHP code to give me the raw response from the Akismet server(s), and these are the two results—this is the exact code and return values Akismet is returning:
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 12 Feb 2010 06:39:52 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-akismet-server: 192.168.7.4
4
true
0
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 12 Feb 2010 06:40:45 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-akismet-server: 192.168.6.46
5
false
0
Do you see? Akismet has changed their return values. They are no longer simply "true" and "false", they are pre- and appended with digits on separate lines.
Of course, more fool me for coding my PHP to look explicitly for "true" and "false" only—once I saw this, I was able to fix the problem quickly. (Changing the comparison from "string equality" to "string contains".) Spam checking fixed.
The weird thing is, I can’t seem to find anything about this online (other than a comment on another blog so far), and I can’t figure why this is what’s being returned to my PHP while cURL reported only "true" and "false". Perhaps something to do with UTF encoding? Multi-byte strings? I don’t know.
And why now? There have been no server or PHP changes on my end and like I said, it’s been working fine for years. Literally.
Anyway, I posted this here to help out other people potentially having troubles with their Akismet code.