pablosanches / hcaptcha
A simple wrapper for hCaptcha
dev-master
2021-09-30 11:02 UTC
Requires
- pablosanches/owl: 1.0.*
This package is auto-updated.
Last update: 2024-12-29 06:52:22 UTC
README
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 ;)