PHP code example of resolventa / stopforumspam-php-api

1. Go to this page and download the library: Download resolventa/stopforumspam-php-api 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/ */

    

resolventa / stopforumspam-php-api example snippets



use Resolventa\StopForumSpamApi\ResponseAnalyzer;
use Resolventa\StopForumSpamApi\ResponseAnalyzerSettings;
use Resolventa\StopForumSpamApi\StopForumSpamApi;
use Resolventa\StopForumSpamApi\Exception\StopForumSpamApiException;

hecked
 */
$stopForumSpamApi
    ->checkEmail('[email protected]')
    ->checkIp('135.34.23.33')
    ->checkUsername('someGreatUsername');

/**
 * Get Response from StopForumSpam service
 */
$response = $stopForumSpamApi->getCheckResponse();

/**
 * You can analyze response on your own or use Resolventa\StopForumSpamApi\ResponseAnalyzer to make decision
 * See ResponseAnalyzer usage below
 */
var_dump($response);

/**
 * Create analyzer instance with $response and default analyser settings
 *
 * Or customize analyser settings to your needs
 * $settings = new ResponseAnalyzerSettings();
 * $settings->setMinSpamFlagsCount(2);
 * $settings->setMinFlagAppearanceFrequency(10);
 * $settings->setFlagLastSeenDaysAgo(14);
 * $settings->setConfidenceThreshold(70);
 */
$analyzer = new ResponseAnalyzer(new ResponseAnalyzerSettings());

try {
    if($analyzer->isSpammerDetected($response)) {
        echo "Spam user detected. \n";
    } else {
        echo "User is ok. \n";
    }
} catch (StopForumSpamApiException $e) {
    echo 'Bad response: ',  $e->getMessage(), "\n";
    exit();
}

// Create analyzer settings with default values
$settings = new ResponseAnalyzerSettings();

// Update any setting with your preferable value
$settings->setMinSpamFlagsCount(2);
$settings->setMinFlagAppearanceFrequency(10);
$settings->setFlagLastSeenDaysAgo(14);
$settings->setConfidenceThreshold(70);

// Start analyzer with given settings
$analyzer = new ResponseAnalyzer(new ResponseAnalyzerSettings());

// Validate response with the give analyzer settings
if($analyzer->isSpammerDetected($response)) {
    // Throw away that spam registration
}

// Instantiate StopForumSpamApi with API key
$stopForumSpamApi = new StopForumSpamApi(self::API_KEY);

// Submit report
$result = $stopForumSpamApi->submitSpamReport(string $username, string $ip, string $email, string $evidence);
bash
composer