PHP code example of zexbre / spam-protect

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

    

zexbre / spam-protect example snippets




use ZexBre\SpamProtect\Factory\ReCaptchaVersion2Factory;

// (1/3) preparation
$spamProtect = ReCaptchaVersion2Factory::getProtector([
    'reCaptchaSecretKey' => [RECAPTCHA-SECRET-KEY],
    'gReCaptchaResponse' => [RECAPTCHA-RESPONSE],
    'acceptLanguage' => [ACCEPT-LANGUAGE-HEADER], // optional
    'httpReferer' => [HTTP-REFERER-HEADER], // optional, see '$_SERVER["HTTP_REFERER"]'
    'httpUserAgent' => [HTTP-USER-AGENT-HEADER], // optional, see '$_SERVER["HTTP_USER_AGENT"]'
]);

// (2/3) verification
$spamProtect->verify();

// (3/3) validation
$isHuman = $spamProtect->isHuman(); // boolean
$isRobot = $spamProtect->isRobot(); // boolean
$isValidResponse = $spamProtect->isValidResponse(); // boolean
$isInvalidResponse = $spamProtect->isInvalidResponse(); // boolean
$errors = $spamProtect->getErrors(); // array
html

 use ZexBre\SpamProtect\Factory\ReCaptchaVersion2Factory;