PHP code example of coercive / app

1. Go to this page and download the library: Download coercive/app 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/ */

    

coercive / app example snippets



# in works ...


$recaptcha = new ReCaptcha;

$recaptcha
   ->setPublicKey("RECAPTCHA_PUBLIC_KEY")
   ->setPrivateKey("RECAPTCHA_SECRET_KEY")

if (!$recaptcha->validateAndPersist($_POST['inputTokenToCheck'])) {
    die('invalid');
}

$recaptcha->threshold(0.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'])

$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;
   });