1. Go to this page and download the library: Download tmi/anti-spam 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/ */
use Tmi\AntiSpam\HoneypotFields;
use Tmi\AntiSpam\Service\SpamGuard;
$reason = $spamGuard->detect(
(string) $form->get(HoneypotFields::WEBSITE)->getData(),
(string) $form->get(HoneypotFields::LOADED_AT)->getData(),
(string) $form->get(HoneypotFields::JS_TOKEN)->getData(),
MyType::JS_TOKEN,
);
if (null !== $reason) {
// silently drop — no flash, no persistence
}
use Tmi\AntiSpam\Service\TurnstileVerifier;
final class AppTurnstileVerifier extends TurnstileVerifier
{
public function __construct(HttpClientInterface $turnstileClient, string $secret, LoggerInterface $logger)
{
parent::__construct($turnstileClient, $secret, $logger, ['example.com', 'www.example.com']);
}
}
// in the controller, BEFORE the honeypot check:
$reason = $verifier->verify(
$request->request->getString('cf-turnstile-response'),
$request->getClientIp() ?? '',
'newsletter', // the action your widget declared
);
// null = ok; otherwise 'missing-token'|'invalid-token'|'timeout-or-duplicate'|'hostname-mismatch'|'action-mismatch'|'network-error'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.