Download the PHP package myra-security-gmbh/eu-captcha without Composer
On this page you can find all versions of the php package myra-security-gmbh/eu-captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download myra-security-gmbh/eu-captcha
More information about myra-security-gmbh/eu-captcha
Files in myra-security-gmbh/eu-captcha
Package eu-captcha
Short Description EU captcha protects your website/API against abuse like form spam and credential stuffing
License
Informations about the package eu-captcha
EU-Captcha PHP client
Privacy-first, no-cookie, no-manual-interaction bot protection for PHP 8.0+ applications. Automatically filters bots, spam, and credential-stuffing attempts without requiring any user interaction.
Requirements
- PHP 8.0 or later
- Guzzle (
guzzlehttp/guzzle^6.0 or ^7.0)
Installation
Note: This package requires PHP 8.0 or newer. Always install it with the
^2.0.1constraint shown below (keep the quotes, so Windowscmd.exedoes not drop the^). The constraint excludes 2.0.0, which sends request fields the verification API rejects, so every validation fails. Without any constraint, Composer on PHP 5.x–7.x silently falls back to the legacy 1.x release, whose API (EU_Captchaclass) does not match this README. On PHP 7.x or older, call the verification API directly instead.
Upgrading from 2.0.0? That release cannot verify tokens at all; see the changelog for what changed in 2.0.1. Run composer update myra-security-gmbh/eu-captcha so an existing lock file moves off 2.0.0.
Getting credentials
- Register at app.eu-captcha.eu
- Create a site and copy the sitekey and secret from the dashboard
Quick start
Using a SPA framework? The script tag and
<div>approach below is for server-rendered pages. If you are building with React, Vue, or Angular, use the matching npm package for the frontend widget and continue to use this package for server-side verification only. See SPA integration guides for details.
Add the widget script to any page that contains a form you want to protect:
Place the widget inside your form:
Verify the submitted token on your server:
validate() reads the token automatically from the request body — $_POST['eu-captcha-response'], falling back to the body of a JSON request (application/json or a +json type such as application/vnd.api+json), where PHP leaves $_POST empty (e.g. Laravel or SPA clients) — and the client IP from server headers, so no extra wiring is needed in the common case. For full control (custom field names, or a framework-aware client IP such as Laravel's $request->ip()), pass the token and IP explicitly — see the Laravel section below.
Configuration options
All options are passed as named constructor arguments.
| Option | Type | Default | Description |
|---|---|---|---|
sitekey |
string | — | Required. Public sitekey from the dashboard. |
secret |
string | — | Required. Secret key from the dashboard. Never expose this client-side. |
failDefault |
bool | true |
Return value used for both network and token state when the API cannot be reached. true = fail open (allow on error); false = fail closed (deny on error). |
checkCdnHeaders |
bool | true |
When true, the client IP is resolved from CDN/proxy headers (HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, HTTP_X_REAL_IP) before falling back to REMOTE_ADDR. Set to false when your server is not behind a proxy, or when you pass the IP explicitly. |
verifyUrl |
string | (production URL) | Override the EU Captcha verify endpoint. Useful for testing. |
credentialsUrl |
string | (production URL) | Override the EU Captcha verify-credentials endpoint. |
client |
?Client |
null |
Optional Guzzle client instance for custom configuration or testing. |
The result object
validate() returns an EuCaptchaResult with three methods:
| Method | Returns true when… |
|---|---|
success() |
The API was reached and the token is valid. |
successNetwork() |
The API call completed without a network or transport error. |
successToken() |
The API reported the submitted token as valid. |
Checking both states separately lets you distinguish a user failing the captcha from an API outage:
Explicit token and IP
Pass the token and client IP explicitly when you need full control (e.g. non-standard form field names or API endpoints):
Verifying credentials
Use verifyCredentials() to confirm your sitekey and secret are valid without submitting a client token. This is useful for startup or configuration checks:
verifyCredentials() returns false on any network or API error rather than throwing, so it is safe to call during application initialisation.
Symfony
Type-hint EuCaptchaInterface in your services and controllers so Symfony can autowire the client without coupling your code to the concrete class.
Register EuCaptcha as a service and alias the interface to it in config/services.yaml:
Inject the interface into a controller:
$request->getClientIp() respects Symfony's trusted-proxy configuration, so the real visitor IP is forwarded correctly when running behind a CDN or load balancer. Pass the User-Agent as a third argument to validate() if you want to forward it to the API as well.
Laravel
Store credentials in .env and expose them through config/services.php — the Laravel convention for third-party credentials:
.env
config/services.php
Controller
$request->ip() respects Laravel's trusted-proxy configuration, so the real visitor IP is forwarded correctly when running behind a load balancer or CDN.
Form Request
For reusable validation across multiple controllers, add the CAPTCHA check to a dedicated FormRequest:
Inject ContactRequest instead of Request in your controller method — Laravel resolves and validates it automatically before the method body runs:
Further reading
- Full documentation
- PHP module guide
- Server-side verification reference
- SPA integration guides (React / Next.js, Vue / Nuxt, Angular)
License
BSD 2-Clause. See LICENSE for details.