dev-master
9999999-dev http://coercive.frCoercive App
MIT GNU
The Requires
- php >=7.0
- coercive/session ^0
Wallogit.com
2017 © Pedro Peláez
Coercive App
!!! IN WORKS !!!, (*1)
composer require coercive/app
# in works ...
Load class and set your keys, (*2)
$recaptcha = new ReCaptcha;
$recaptcha
->setPublicKey("RECAPTCHA_PUBLIC_KEY")
->setPrivateKey("RECAPTCHA_SECRET_KEY")
Check if your token is valid, (*3)
if (!$recaptcha->validateAndPersist($_POST['inputTokenToCheck'])) {
die('invalid');
}
Optional: by default is V2 ; set threshold if you wan't to use reCaptcha V3, (*4)
$recaptcha->threshold(0.5)
Optional: use storage data to optimize your quota, (*5)
$recaptcha->setStoreCallback(function($result) {
/* your storage logic here */
})
$recaptcha->setRetrieveCallback(function() {
/* your retrieve logic here */
})
/* use `validateAndPersist()` to trigger your callbacks */
$recaptcha->validateAndPersist($_POST['inputTokenToCheck'])
Full example with session storage logic, (*6)
$recaptcha
->setPublicKey("RECAPTCHA_PUBLIC_KEY")
->setPrivateKey("RECAPTCHA_SECRET_KEY")
->threshold(0.5)
->setStoreCallback(function($result) {
$_SESSION['recaptcha']['result'] = $result;
$_SESSION['recaptcha']['timestamp'] = time();
})
->setRetrieveCallback(function () {
if(!isset($_SESSION['recaptcha'])) {
return null;
}
if(($_SESSION['recaptcha']['timestamp'] ?? 0) + (24 * 60 * 60) < time()) {
return null; # example 1 day in second before recheck
}
return $_SESSION['recaptcha']['result'] ?? false;
});
Coercive App
MIT GNU