1. Go to this page and download the library: Download marshmallow/bot-shield 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 Illuminate\Foundation\Configuration\Exceptions;
use Marshmallow\BotShield\Facades\BotShield;
->withExceptions(function (Exceptions $exceptions) {
BotShield::handles($exceptions);
})
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Marshmallow\BotShield\Concerns\HardensAgainstBots;
class Handler extends ExceptionHandler
{
use HardensAgainstBots;
public function register(): void
{
$this->hardenAgainstBots();
}
}
use Livewire\Component;
use Marshmallow\BotShield\Livewire\BlocksBots;
use Marshmallow\BotShield\Livewire\RateLimitsSubmissions;
use Marshmallow\BotShield\Livewire\ValidatesRecaptcha;
class ContactForm extends Component
{
public string $gRecaptchaResponse = '';
#[BlocksBots]
#[ValidatesRecaptcha]
#[RateLimitsSubmissions(attempts: 3, seconds: 60)]
public function submit(): void
{
// Only runs once every check passes.
}
}
use Marshmallow\BotShield\Concerns\ProtectsAgainstBots;
use Marshmallow\BotShield\Concerns\ProtectsAgainstSpam;
use Spatie\Honeypot\Http\Livewire\Concerns\HoneypotData;
class ContactForm extends Component
{
use ProtectsAgainstBots;
use ProtectsAgainstSpam;
public HoneypotData $honeypotData;
public function mount(): void
{
$this->honeypotData = new HoneypotData;
}
public function submit(): void
{
$this->protectAgainstBots();
$this->protectAgainstSpam();
}
}
use Illuminate\Foundation\Http\FormRequest;
use Marshmallow\BotShield\Concerns\ValidatesRecaptcha;
class ContactRequest extends FormRequest
{
use ValidatesRecaptcha;
public function rules(): array
{
return array_merge($this->recaptchaRules('contact'), [
'email' => ['
use Marshmallow\BotShield\Rules\Recaptcha;
'g-recaptcha-response' => [new Recaptcha],
#[On('formSubmitted')]
public function submit(?string $token = null): void
use Marshmallow\BotShield\Facades\BotShield;
$shield = BotShield::fake();
$shield->captchaPasses(0.9); // or captchaFails(), captchaScores(0.2), captchaUnavailable()
// ... exercise your form ...
$shield->assertChallenged();
$shield->assertCaptchaPassed();
$shield->assertBlocked('contact');
$shield->assertNotBlocked();
$shield->assertHoneypotTripped();
$shield->assertRateLimited();
BotShield::fake('google-v2');
BotShield::fake()->withoutProtection();
use Marshmallow\BotShield\Facades\BotShield;
if (BotShield::isBot()) {
// Skip the expensive thing, or the analytics hit.
}
BotShield::isBot($request); // or pass a specific request
BotShield::detector(); // the resolved detector, rules
use Illuminate\Http\Request;
use Marshmallow\BotShield\Contracts\BotDetector;
class IpRangeDetector implements BotDetector
{
public function isBot(Request $request): bool
{
return YourIpRanges::contains($request->ip());
}
}