Setup

Service Providers

Though originally created for use with the Akismet service, the Akismet API is also used by other spam-filtering services. Services_Akismet2 works with any service that uses the Akismet API. To use Services_Akismet2 with other spam-filtering service providers, specify the API server in either the constructor, or by using the setConfig() method.

For example:

<?php

require_once 'Services/Akismet2.php';

// set service provider in constructor
$akismet = new Services_Akismet2('http://example.com''AABBCCDDEEFF', array(
    
'apiServer' => 'antispam.example.com'
));

// set service provider using setConfig() method
$akismet = new Services_Akismet2('http://example.com''AABBCCDDEEFF');
$akismet->setConfig('apiServer''antispam.example.com');

// for a service provider that uses a non-standard port (8080)
$akismet = new Services_Akismet2('http://example.com''AABBCCDDEEFF');
$akismet->setConfig('apiServer''antispam.example.com')
        ->
setConfig('apiPort'8080);

?>

Popular spam-filtering service providers using the Akismet API include:

API Keys

All requests using the Akismet API must be verified using an API key. The API key is usually tied to a particular website and ensures the user is allowed to use the service (which is not free to provide). Most service providers offer API keys free of charge for personal or low-volume use, and offer licensing for commercial or high-volume applications.

API keys are specific to a particular service provider. If you switch spam-filtering service providers, you will need to acquire an API key for the particular service.

The format of the API key may vary between service providers. The API key itself is specified in the constructor. A Services_Akismet2_InvalidApiKeyException will be thrown when a request is made using an invalid API key.

Testing Your API Key

After you have acquired an API key, you may want to test it. A comment with the author set to viagra-test-123 should always be detected as spam, so it is a good way to make sure things are working properly.

<?php

require_once 'Services/Akismet2.php';
require_once 
'Services/Akismet2/Comment.php';

$comment = new Services_Akismet2_Comment(array(
    
'comment_author' => 'viagra-test-123',
    
'user_ip'        => '127.0.0.1',
    
'user_agent'     => 'just testing',
    
'referrer'       => 'http://example.com'
));

$akismet = new Services_Akismet2('http://myblog.example.com''AABBCCDDEEFF');
if (
$akismet->isSpam($comment)) {
    echo 
'Everything is working properly.';
} else {
    echo 
'Something\'s not right!';
}

?>
Introduction (Previous) The Comment Class (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.