neoan3-apps / hcaptcha
hcaptcha PHP implementation
v1.1.0
2020-08-04 00:19 UTC
Requires
- ext-json: *
- neoan3-apps/curl: ^1.0
Requires (Dev)
- phpunit/phpunit: ^8.5.8
This package is auto-updated.
Last update: 2024-12-04 09:21:02 UTC
README
⚠️ I'm not affiliated in any way with hCaptcha ⚠️
Easy integration of hCaptcha, a service that
- Keeps bots out;
- Earns you money;
- Is privacy conscious.
Quick start
-
Sign up at hCaptcha.
-
Fetch your public key and site key from the settings tab.
-
Get this package
composer require neoan3-apps/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:
\Neoan3\Apps\Hcapture::setEnvironment([ 'siteKey' => 'your-sitekey', 'secret' => 'your-secret', 'apiKey' => 'your-api-key' ]); if(isset($_POST['my-form']) && \Neoan3\Apps\Hcapture::isHuman()) { ... do stuff }
hCapture neoan3 API
Here are some methods for you to use and setup hCaptcha in your project.
Environment setup
For your global environment setup, please use the following methods:
// Set your own secret key setSecret(string $value); // API Key of hCaptcha linked to your account setApiKey(string $value); // Secret site key linked to your site // See: https://docs.hcaptcha.com/api#addnewsitekey setSiteKey(string $value); // With an array of environment variables provided, set all of them // This is a 'shortcut' for all three previous methods setEnvironment(array $environmentVariables);
hCaptcha utils
To retrieve hCaptcha information, here are the methods you will need:
// Check if the hCaptcha verification was successful isHuman(); // Retrieve all statitics of the site corresponding to the // provided variables (an error value is returned in case of // invalid credentials) stats();
Advanced setup
You can have more details about advanced setup on the configuration page of the documentation.