PHP SDK
Server-side captcha token verification for PHP.
Installation
composer require crovly/crovly-phpRequires PHP 8.1+ and the cURL extension.
Basic Usage
use Crovly\Crovly;
$crovly = new Crovly('crvl_secret_YOUR_API_KEY');
$result = $crovly->verify($_POST['crovly-token'], [
'expectedIp' => $_SERVER['REMOTE_ADDR'],
]);
if (!$result->isHuman()) {
http_response_code(403);
die('Captcha verification failed');
}API
new Crovly(secretKey, options?)
| Parameter | Type | Default | Description |
|---|---|---|---|
$secretKey | string | — | Your API key (required) |
$options['baseUrl'] | string | https://api.crovly.com | API base URL |
$options['timeout'] | int | 10 | Request timeout in seconds |
$crovly->verify(token, options?)
| Parameter | Type | Required | Description |
|---|---|---|---|
$token | string | Yes | Token from the widget |
$options['expectedIp'] | string | No | IP to verify against |
VerifyResponse
$result->isHuman(); // bool — shorthand for $result->success
$result->success; // bool
$result->score; // float (0.0–1.0)
$result->ip; // string
$result->solvedAt; // int (Unix ms)
$result->error; // string|nullLaravel Example
// app/Http/Controllers/ContactController.php
use Crovly\Crovly;
class ContactController extends Controller
{
public function store(Request $request)
{
$crovly = new Crovly(config('services.crovly.secret'));
$result = $crovly->verify($request->input('crovly-token'), [
'expectedIp' => $request->ip(),
]);
if (!$result->isHuman()) {
return back()->withErrors(['captcha' => 'Verification failed']);
}
// Process the form...
}
}// config/services.php
'crovly' => [
'site_key' => env('CROVLY_SITE_KEY'),
'secret' => env('CROVLY_SECRET_KEY'),
],WordPress
Install the Crovly WordPress plugin for automatic integration with login, registration, comments, and WooCommerce forms.
- Download from GitHub or install via WordPress plugin manager
- Go to Settings → Crovly
- Enter your Site Key and API Key
- Select which forms to protect
Error Handling
use Crovly\Crovly;
use Crovly\Exceptions\ApiException;
use Crovly\Exceptions\ValidationException;
try {
$result = $crovly->verify($token);
} catch (ValidationException $e) {
// Invalid token format
} catch (ApiException $e) {
// API error (rate limit, auth, etc.)
echo $e->getStatusCode();
}| Exception | Description |
|---|---|
ValidationException | Invalid request data |
ApiException | API returned an error (401, 429, etc.) |
CrovlyException | Base exception class |