1. Go to this page and download the library: Download verifyblind/verifyblind-php 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/ */
verifyblind / verifyblind-php example snippets
VerifyBlind\Cache\FileCache;
use VerifyBlind\Exception\VerifyBlindException;
use VerifyBlind\Verifier;
header('Content-Type: application/json');
$token = json_decode(file_get_contents('php://input'), true)['token'] ?? '';
$vb = new Verifier(['cache' => new FileCache()]);
try {
$result = $vb->verify((string) $token, $consume); // $consume: aşağıda "Nonce kuralı"
} catch (VerifyBlindException $e) {
http_response_code($e->getHttpStatus());
exit(json_encode(['error' => $e->getErrorCode()]));
}
// İmza, nonce ve sorulan doğrulamalar kontrol edildi. Artık cevabı kullanabilirsiniz:
echo json_encode(['ok' => true, 'age' => $result->age()]);
// generate aracısında, VerifyBlind nonce döndürdükten sonra:
$pdo->prepare('INSERT INTO vb_nonces (nonce, asked, expires_at) VALUES (?, ?, ?)')
->execute([$nonce, json_encode(['age' => '18+', 'user_id' => true]), time() + 960]);
// doğrulamada: tek seferlik al-ve-sil
$consume = function (string $nonce) use ($pdo): ?array {
$q = $pdo->prepare('SELECT asked FROM vb_nonces WHERE nonce = ? AND expires_at > ?');
$q->execute([$nonce, time()]);
$asked = $q->fetchColumn();
$d = $pdo->prepare('DELETE FROM vb_nonces WHERE nonce = ?');
$d->execute([$nonce]);
// Satırı yalnız bir istek silebilir; aynı anda gelen tekrar 0 satır görür ve reddedilir.
return ($asked !== false && $d->rowCount() === 1) ? json_decode($asked, true) : null;
};
$raw = file_get_contents('php://input'); // ham gövde; yeniden JSON'a çevirmeyin
try {
$body = $vb->verifyWebhook($raw, $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? null, $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? null);
} catch (VerifyBlindException $e) {
http_response_code($e->getHttpStatus());
exit;
}
// $body['nonce'] her zaman vardır; o nonce'a bağlı veriyi silin ya da işaretleyin.
http_response_code(200);
VerifyBlind\Cache\FileCache;
use VerifyBlind\Exception\VerifyBlindException;
use VerifyBlind\Verifier;
header('Content-Type: application/json');
$token = json_decode(file_get_contents('php://input'), true)['token'] ?? '';
$vb = new Verifier(['cache' => new FileCache()]);
try {
$result = $vb->verify((string) $token, $consume); // $consume: see "Nonce rule" below
} catch (VerifyBlindException $e) {
http_response_code($e->getHttpStatus());
exit(json_encode(['error' => $e->getErrorCode()]));
}
// Signature, nonce and asked validations are checked. Now use the answer:
echo json_encode(['ok' => true, 'age' => $result->age()]);
// in the generate proxy, after VerifyBlind returned the nonce:
$pdo->prepare('INSERT INTO vb_nonces (nonce, asked, expires_at) VALUES (?, ?, ?)')
->execute([$nonce, json_encode(['age' => '18+', 'user_id' => true]), time() + 960]);
// at verification: one-time get-and-delete
$consume = function (string $nonce) use ($pdo): ?array {
$q = $pdo->prepare('SELECT asked FROM vb_nonces WHERE nonce = ? AND expires_at > ?');
$q->execute([$nonce, time()]);
$asked = $q->fetchColumn();
$d = $pdo->prepare('DELETE FROM vb_nonces WHERE nonce = ?');
$d->execute([$nonce]);
// Only one request can delete the row; a parallel replay sees 0 rows and is rejected.
return ($asked !== false && $d->rowCount() === 1) ? json_decode($asked, true) : null;
};
$raw = file_get_contents('php://input'); // the raw body; do not re-encode it
try {
$body = $vb->verifyWebhook($raw, $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? null, $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? null);
} catch (VerifyBlindException $e) {
http_response_code($e->getHttpStatus());
exit;
}
// $body['nonce'] is always present; delete or mark the data tied to that nonce.
http_response_code(200);
bash
composer
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.