ozmaier / cardcaptcha
There is no license information available for the latest version (1.0) of this package.
Playing-card captcha generator and verifier for PHP applications
1.0
2026-07-30 19:34 UTC
Requires
- php: ^8.0
README
Playing-card captcha for PHP with built-in locale files, card sets, and session-backed verification.
Install
composer require ozmaier/cardcaptcha
Quick Start
<?php require __DIR__ . '/vendor/autoload.php'; use Ozmaier\Cardcaptcha\CardCaptcha; $captcha = new CardCaptcha('change-this-secret', 4, 'en', 'default'); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['cc_card']) && is_string($_POST['cc_card'])) { $isValid = $captcha->verifySession($_POST['cc_card']); } else { $challenge = $captcha->createSessionChallenge(); }
createSessionChallenge() stores the expected answer in $_SESSION. verifySession() reads it back and clears it after verification, so the answer never needs to be sent to the browser.
Constructor
new CardCaptcha(string $secret, int $choiceCount = 4, string $locale = 'en', string $cardSet = 'default', ?string $resourceRoot = null)
API
createChallenge()builds a challenge without using the session.createSessionChallenge()builds a challenge and stores the answer in$_SESSION.verify()checks a selected hash against a known answer code.verifySession()checks a selected hash against the session-stored answer.message()returns a localized message such asprompt.supportedLocales()lists bundled locales such asen,fr, andde.supportedCardSets()lists bundled card sets such asdefault.
Custom Resources
$captcha = new CardCaptcha('change-this-secret', 4, 'it', 'tarot', __DIR__ . '/cardcaptcha-resources');
The package example is in index.php.