PHP code example of gothick / php-akismet

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

    

gothick / php-akismet example snippets


    $client = new \Gothick\AkismetClient\Client(
        "http://example.com",   // Your website's URL (this becomes Akismet's "blog" parameter)
        "Example Forum",        // Your website or app's name (Used in the User-Agent: header when talking to Akismet)
        "1.2.3",                // Your website or app's software version (Used in the User-Agent: header when talking to Akismet)
        "YOUR KEY HERE"         // Your Akismet API key
    );

    // See https://akismet.com/development/api/#comment-check for all available parameters
    $params = [
        "user_ip" => "203.0.113.4", // IP address of person posting the comment
        "user_agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8", // User-Agent header of the commenter
        "comment_type" => "forum-post",
        "comment_author" => "Spammy McSpamface",
        "comment_content" => "I'm an evil spammy message"
    ]

    // $result will be of type \Gothick\AkismetClient\Result\CommentCheckResult.php
    // Akismet really wants to see your $_SERVER variables. "This data is highly useful to
    // Akismet. How the submitted content interacts with the server can be very telling,
    // so please 

    // ...get $result from client as above...
    // If it's blatant spam that Akismet thinks you can discard without human
    // intervention (see https://blog.akismet.com/2014/04/23/theres-a-ninja-in-your-akismet/)
    $is_blatant_spam = $result->isBlatantSpam();

    // Get the X-akismet-pro-tip header, if present
    if ($result->hasProTip()) {
        $pro_tip = $result->getProTip();
    }

    // Get the X-akismet-debug-help header, if present
    if ($result->hasDebugHelp()) {
        $debug_help = $result->getDebugHelp();
    }

    $client = new \Gothick\AkismetClient\Client(
        "http://example.com",   // Your website's URL (this becomes Akismet's "blog" parameter)
        "Example Forum",        // Your website or app's name (Used in the User-Agent: header when talking to Akismet)
        "1.2.3",                // Your website or app's software version (Used in the User-Agent: header when talking to Akismet)
        "YOUR KEY HERE"         // Your Akismet API key
    );

    // $result will be of type \Gothick\AkismetClient\Result\VerifyKeyResult
    $result = $client->verifyKey();
    $api_key_is_valid = $result->isValid(); // Boolean

    // Can also check pro tip and debug help as above.

    $client->submitHam($params, $_SERVER);
    // OR
    $client->submitSpam($params, $_SERVER);