PHP code example of helgesverre / spamprotection

1. Go to this page and download the library: Download helgesverre/spamprotection 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/ */

    

helgesverre / spamprotection example snippets




declare(strict_types=1);

use Helge\SpamProtection\SpamProtection;
use Helge\SpamProtection\Types;
use Helge\SpamProtection\Exception\ApiCheckException;

p, email, username)
 */
var_dump($spamProtector->check(Types::EMAIL, "[email protected]"));
var_dump($spamProtector->check(Types::IP, "8.8.8.8"));
var_dump($spamProtector->check(Types::USERNAME, "helgesverre"));

/**
 * For convenience some wrapper methods are provided, 
 * they simply pass the data long to check()
 */
var_dump($spamProtector->checkEmail("[email protected]"));
var_dump($spamProtector->checkIP("8.8.8.8"));
var_dump($spamProtector->checkUsername("spammer"));



use Helge\SpamProtection\SpamProtection;
use Helge\SpamProtection\Types;

onvenience
    const THRESHOLD_STRICT = 1;
    const THRESHOLD_HIGH = 3;
    const THRESHOLD_MEDIUM = 5;
    const THRESHOLD_LOW = 10;
*/

$spamProtector = new SpamProtection(SpamProtection::THRESHOLD_STRICT);

// or 

$spamProtector = new SpamProtection();
$spamProtector->setFrequencyThreshold(SpamProtection::THRESHOLD_HIGH);



use Helge\SpamProtection\SpamProtection;
use Helge\SpamProtection\Types;

onvenience
    const TOR_ALLOW = true;
    const TOR_DISALLOW = false;
*/

$spamProtector = new SpamProtection(SpamProtection::THRESHOLD_STRICT, SpamProtection::TOR_DISALLOW);

// or 

$spamProtector = new SpamProtection();
$spamProtector->setAllowTorNodes(false);

use Helge\SpamProtection\Exception\ApiCheckException;
use Helge\SpamProtection\Exception\ApiKeyMissingException;
use Helge\SpamProtection\Exception\SubmissionFailedException;

try {
    $isSpam = $spamProtector->checkEmail("[email protected]");
} catch (ApiCheckException $e) {
    // Handle API connection or response errors
    error_log("API check failed: " . $e->getMessage());
}

try {
    $spamProtector->submitReport($username, $ip, $evidence, $email);
} catch (ApiKeyMissingException $e) {
    // API key is 

// v1.x
$spamProtector->check("email", "[email protected]");

// v2.0
$spamProtector->check(Types::EMAIL, "[email protected]");