PHP code example of omines / akismet

1. Go to this page and download the library: Download omines/akismet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

omines / akismet example snippets


$httpClient = HttpClient::create();

$akismet = new Akismet($httpClient, 'Akismet API key', 'https://www.example.org/');

$message = (new AkismetMessage())
    ->setUserIP('1.2.3.4')
    ->setType(MessageType::COMMENT)
    ->setContent('Some spammy message')
    ->setAuthorEmail('[email protected]')
;

$message = AkismetMessage::fromRequest($symfonyRequest);
// or
$message = AkismetMessage::fromPSR7Request($psr7Request);

$response = $akismet->check($message);
if ($response->isSpam()) {
    if ($response->shouldDiscard()) {
      // Akismet believes this to be the most pervasive and worst spam, not even worthy of moderation 
    } else {
      // The message is considered spam, so it should either be refused or manually reviewed
    }
}

$response = $this->akismet->submitHam($message);
$response = $this->akismet->submitSpam($message);

$response = $this->akismet->usageLimit();
if ($response->getPercentage() > 50) {
    @trigger_error('Used up more than half the usage limit', E_USER_WARNING);
}
$response = $this->akismet->activity(limit: 100);
foreach ($response->getMonths() as $month => $activities) {
   // Do stuff
}