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

Maintainers

Package info

github.com/ozMaier/cardcaptcha

pkg:composer/ozmaier/cardcaptcha

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0 2026-07-30 19:34 UTC

This package is auto-updated.

Last update: 2026-07-30 19:38:14 UTC


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 as prompt.
  • supportedLocales() lists bundled locales such as en, fr, and de.
  • supportedCardSets() lists bundled card sets such as default.

Custom Resources

$captcha = new CardCaptcha('change-this-secret', 4, 'it', 'tarot', __DIR__ . '/cardcaptcha-resources');

The package example is in index.php.