1. Go to this page and download the library: Download shevabam/simple-hcaptcha 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/ */
shevabam / simple-hcaptcha example snippets
SimpleHcaptcha\Hcaptcha;
// Initialize with your site key and secret key
$hcaptcha = new Hcaptcha('your-site-key', 'your-secret-key');
// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$hcaptchaResponse = $_POST['h-captcha-response'] ?? '';
// Remote IP is optional, but recommended
if ($hcaptcha->isValid($hcaptchaResponse, $_SERVER['REMOTE_ADDR'])) {
// CAPTCHA validation passed, process the form
echo "Form submitted successfully!";
} else {
// CAPTCHA validation failed
echo "CAPTCHA verification failed: " . $hcaptcha->getError();
}
}
$hcaptcha = new Hcaptcha('your-site-key', 'your-secret-key', [
'theme' => 'dark',
'size' => 'normal',
'language' => 'fr'
]);
// Or using setter methods
$hcaptcha
->setTheme('dark')
->setSize('normal')
->setLanguage('fr');
$hcaptcha->getScript();
$hcaptcha->display();
if ($hcaptcha->isValid($_POST['h-captcha-response'], $_SERVER['REMOTE_ADDR'])) {
// CAPTCHA validation passed, process the form
echo "Form submitted successfully!";
} else {
// CAPTCHA validation failed
echo "CAPTCHA verification failed: " . $hcaptcha->getError();
}
if (!$hcaptcha->isValid($response)) {
$error = $hcaptcha->getError();
// Handle the error
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.