hCaptcha Wrapper
Quick start
- Sign up at hCaptcha.
- Fetch your public key and site key from the settings tab.
- Get this package
composer require pablosanches/hcaptcha
- Set up your front end as:
<head>
<script src="https://hcaptcha.com/1/api.js" async defer></script>
...
</head>
<body>
<form action="endpoint.php" method="post">
...
<div class="h-captcha" data-sitekey="your-sitekey"></div>
<input type="submit" value="send">
</form>
</body>
- Now in your PHP back end:
require('../vendor/autoload.php');
use PabloSanches\hCaptcha;
$hCaptcha = new hCaptcha('your-secret-key');
$hCaptchaResult = $hCaptcha->challenge($_POST['h-captcha-response']);
$isHuman = $hCaptchaResult->isHuman(); // True or False
if (!$isHuman) {
$errors = $hCaptchaResult->getErrors(); // An array with all errors
}
Enjoy it ;)