Zum Seiteninhalt springen

phoque.de

phoque.de - Webdesign Fotografie Technologie

Defensio-Class

Why Defensio?

I have just finished writing the first version of a PHP4-Class for the Anti-Blogspam-Service Defensio. Defensio basically works similar to Akismet while being less restrictive.

Both systems work by you sending the comments you recieve to Akismet's resp. Defensio's server and letting it evaluate its "spaminess". Both services then will tell you if this comment is spam. Additionally, Defensio also tells you its "spaminess" (as a decimal number between 0 and 1 and not just "yes" and "no") and a unique comment-"signature" for later identification.
That way, you may for example display spam-comments using different colors to tag them by their spaminess.

An Example

<?php
require('defensio.class.php');
$comment = array(
'article-date' => '2007/05/21',
'comment-author' => 'Nils',
'comment-type' => 'comment',
// The following values are optional but STRONGLY RECOMMENDED!
'user-ip' => 'xxx.xxx.xxx.xxx',
'comment-content' => 'Hey... how are you? Enjoying your Vacations? How was Stockholm?',
'comment-author-email' => 'xxxxxxxxx@gmail.com',
'comment-author-url' => 'http://www.phoque.de/blog/',
'permalink' => 'http://www.yourpage.com/yourblogpost.url',
'referer' => 'http://www.yourpage.com/yourblogpost.url'
);
$defensio = new Defensio('http://www.yourpage.com/', 'YOUR_DEFENSIO_KEY');
if($defensio->errorsExist()) {
var_dump($defensio->getErrors());
} else {
list($spam, $spaminess, $signature) = $defensio->auditComment($comment);
if(!$spam) {
echo "Not spam! Signature:" . $signature;
} else {
echo "This seems to be spam... Spamminess:" . $spaminess;
}
}
?>

Sorry for the messed up layout... :-)

Download

So this is the initial release of this class, licensed under the LGPL-License.

Feedback, code-modifications and criticism is highly welcome: here!

Download v0.3

Changelog

v0.3: Changed Protocol to HTTP 1.0, improves speed on some servers by almost a minute(!) per request