Server-side verification is required to ensure the CAPTCHA response is valid and not forged. This step should always be performed on your backend before processing any form submission.
Below is a simple PHP implementation you can copy or adapt into your project.
1. Create a CAPTCHA Service Class
Create a reusable class (e.g. C3Captcha) to handle verification requests:
<?php
namespace App\Util;
use camilord\utilus\Net\Qurl;
class C3Captcha
{
const BASE_URL = 'https://captcha.camilord.com';
private ?string $error_message;
public function __construct(
private string $secret_key
) { }
public function getErrorMessage(): ?string {
return $this->error_message;
}
public function verify($inpur_response)
{
$url = self::BASE_URL.'/v1/verify';
$response = Qurl::post($url, [
'secret_key' => $this->secret_key,
'response_token' => $inpur_response,
]);
$this->error_message = $response['message'] ?? null;
return (($response['success'] ?? false) === true);
}
};
2. Use It in Your Form Validation
When processing your form submission, retrieve the CAPTCHA response from POST data and validate it using your class:
<?php
use App\Util\C3Captcha;
$c3_captcha_response = $_POST['c3-captcha-response'] ?? null;
$captcha = new C3Captcha($_ENV['CAPTCHA_SECRET_KEY'])
if (!$captch->verify($c3_captcha_response)) {
echo $captcha->getErrorMessage(); // error, validation incorrect or failed
} else {
// next process
}
3. How It Works
- The user completes the CAPTCHA on the frontend
- A
c3-captcha-response token is sent with the form
- Your server sends this token to C3.CAPTCHA verification API
- The API returns a success or failure response
- Your application decides whether to proceed or reject the request
4. Result
Once integrated, your form is protected against automated submissions and bot attacks with minimal setup and no additional complexity.