PHP code example of geekybones / fraud-defense-bundle

1. Go to this page and download the library: Download geekybones/fraud-defense-bundle 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/ */

    

geekybones / fraud-defense-bundle example snippets


GeekyBones\FraudDefenseBundle\FraudDefenseBundle::class => ['all' => true],

use GeekyBones\FraudDefenseBundle\Form\RecaptchaType;

$builder->add('captcha', RecaptchaType::class, [
    'action' => 'login',
]);

use GeekyBones\FraudDefenseBundle\Defense\Contract\RecaptchaAssessmentInterface;
use GeekyBones\FraudDefenseBundle\Defense\DefenseAssessmentException;

public function __construct(
    private readonly RecaptchaAssessmentInterface $recaptcha,
) {}

try {
    $result = $this->recaptcha->assess(
        token: $request->request->get('recaptcha_token'),
        action: 'login',
    );
} catch (DefenseAssessmentException $e) {
    // API error, invalid/expired token, or incomplete response
}

if (!$result->hasPassed()) {
    // score too low, action mismatch, or hostname mismatch
}