1. Go to this page and download the library: Download wabeo/gaitcha 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/ */
wabeo / gaitcha example snippets
use Gaitcha\AbstractEndpoint;
use Gaitcha\Config;
class CaptchaEndpoint extends AbstractEndpoint
{
/** Send the initialization payload as JSON. @param array $data Response payload. @return void */
protected function sendJsonResponse(array $data): void
{
header('Content-Type: application/json');
header('Cache-Control: no-store');
echo json_encode($data);
}
/** Read the request body, including a proof-of-work solution when present. @return void */
public function handle(): void
{
$request = json_decode((string) file_get_contents('php://input'), true);
$this->sendJsonResponse($this->handleInit(is_array($request) ? $request : []));
}
}
$config = new Config(['secret' => (string) getenv('GAITCHA_SECRET')]);
(new CaptchaEndpoint($config))->handle();
use Gaitcha\Config;
use Gaitcha\ValidationOrchestrator;
$config = new Config(['secret' => (string) getenv('GAITCHA_SECRET')]);
$result = (new ValidationOrchestrator($config))->validate($_POST);
if ($result->isAccepted()) {
// Continue with your application's field validation and form processing.
} else {
// Show a retry message. Use $result->getReason() for diagnostics.
}
use Gaitcha\Config;
use Gaitcha\FileTokenStore;
$config = new Config([
'secret' => (string) getenv('GAITCHA_SECRET'),
'pow' => true,
'anti_replay' => true,
'token_store' => new FileTokenStore('/private/writable/path/gaitcha-tokens.json'),
]);