PHPackages                             jacopovalanzano/php-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. jacopovalanzano/php-captcha

AbandonedLibrary[Authentication &amp; Authorization](/categories/authentication)

jacopovalanzano/php-captcha
===========================

A portable captcha.

1.7.26(4y ago)721↓83.3%MITPHPPHP ^5.4|^7.0|^8.0

Since May 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jacopovalanzano/php-captcha)[ Packagist](https://packagist.org/packages/jacopovalanzano/php-captcha)[ Docs](https://github.com/jacopovalanzano/php-captcha)[ RSS](/packages/jacopovalanzano-php-captcha/feed)WikiDiscussions main Synced 2mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP Captcha
===========

[](#php-captcha)

Portable PHP class for creating simple captchas. One file. Great for simple projects.

[![captcha1](https://camo.githubusercontent.com/45f837aad5e454f7c9d34ed64ce4e40b411a6ca7fb4387979da551168eb4f200/68747470733a2f2f692e696d6775722e636f6d2f43616b5867446a2e676966)](https://camo.githubusercontent.com/45f837aad5e454f7c9d34ed64ce4e40b411a6ca7fb4387979da551168eb4f200/68747470733a2f2f692e696d6775722e636f6d2f43616b5867446a2e676966)

[![captcha2](https://camo.githubusercontent.com/e015db9d4d52ea41876fa8e43cecd890811e501187ccd552772299479a2bb5ac/68747470733a2f2f692e6962622e636f2f4236745a6330742f657a6769662d342d356433353337363562342e676966)](https://camo.githubusercontent.com/e015db9d4d52ea41876fa8e43cecd890811e501187ccd552772299479a2bb5ac/68747470733a2f2f692e6962622e636f2f4236745a6330742f657a6769662d342d356433353337363562342e676966)

**NOTE**: this captcha is not a final solution to combat bots, but will stop avid and raging attackers.

For comparison, below is an example of a *captcha* used by **tesla.com**:

[![tesla-captcha](https://camo.githubusercontent.com/b08d9e1fe8fc54541d088021860d0198e364015bb832da464e8d3087d62f5fe6/68747470733a2f2f692e696d6775722e636f6d2f746b636f674b792e706e67)](https://camo.githubusercontent.com/b08d9e1fe8fc54541d088021860d0198e364015bb832da464e8d3087d62f5fe6/68747470733a2f2f692e696d6775722e636f6d2f746b636f674b792e706e67)

Microsoft ([live.com](live.com)):

[![live.com-captcha](https://camo.githubusercontent.com/c08bc30377165aa7136d362348581fc9838860bc361fa2d9b73842a00c37d19c/68747470733a2f2f692e696d6775722e636f6d2f5979397178626b2e706e67)](https://camo.githubusercontent.com/c08bc30377165aa7136d362348581fc9838860bc361fa2d9b73842a00c37d19c/68747470733a2f2f692e696d6775722e636f6d2f5979397178626b2e706e67)

Installation
------------

[](#installation)

Install with composer, or use the contents of the **src** folder.

```
composer require jacopovalanzano/php-captcha
```

Requires PHP ^5.4 and [PHP-GD](https://www.php.net/manual/en/book.image.php).

Usage
-----

[](#usage)

The captcha is a binary jpeg image, it can be rendered with the "image/jpeg" content-type header.

```
    // Create a new Captcha
    $captcha = new Captcha("My super difficult to read string.");

    // Add 3 lines over and 3 behind the text,
    // then build the image.
    $captcha->linesFront(3)->linesBack(3)->build(175,50); // width, height

    // Returns a string containing the captcha passphrase
    $captcha->getPassphrase(); // Returns "My super difficult to read string."

    // Renders the captcha.
    $captcha->out();

```

Example
-------

[](#example)

A simple example to explain the process of dispatching/retrieving the captcha and its passphrase:

```
    // This file represents the "www.example.com/get_captcha_image" url that generates our captcha

    // ...

    // A list of words
    $attributes = [ "easy", "green", "digital" ];

    // One more list of words
    $nouns = [ "compare", "dungeon", "clip" ];

    // Compose a phrase
    $words = $attributes[array_rand($attributes)]." ".$nouns[array_rand($nouns)];

    // Create a new captcha with some random words
    $captcha = new Captcha($words);

    // Add 2 lines over and 5 behind the text,
    // then build the image.
    $captcha->linesFront(2)->linesBack(5)->build(175,50); // width, height

    // Save the captcha passphrase to session, so it can be retrieved later...
    $_SESSION["captcha_passphrase"] = $captcha->getPassphrase();

    // Render the actual captcha image
    $captcha->out();
```

An example of a form you need to validate, like a login form:

```

```

Or

```
echo '';

```

Match `$_SESSION["captcha_passphrase"]`against the value passed from the input "captcha\_passphrase" in the example above, eg:

```
    // Compare the captcha passphrase with the one submitted
    if($_POST["captcha_passphrase"] !== $_SESSION["captcha_passphrase"]) {
        die("Wrong captcha!");
    }
```

Tests
-----

[](#tests)

Tested with [GNU ocrad](https://www.gnu.org/software/ocrad/) and [Xevil](http://xevil.net)

[![xevil](https://camo.githubusercontent.com/e1aae5a9a3ff7e79166c383ddd6d3c3f2fdf8d22bf802f714bba9098fcf8145e/68747470733a2f2f692e696d6775722e636f6d2f786e6c5a7357562e676966)](https://camo.githubusercontent.com/e1aae5a9a3ff7e79166c383ddd6d3c3f2fdf8d22bf802f714bba9098fcf8145e/68747470733a2f2f692e696d6775722e636f6d2f786e6c5a7357562e676966)

Contributing
------------

[](#contributing)

Pull requests are welcome.

License
-------

[](#license)

[MIT](https://github.com/jacopovalanzano/php-captcha/blob/main/LICENSE)

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1520d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ad85683f5b6072579595b6498f8c15ccd5e68f2f58d529ddb3004fe6271045a?d=identicon)[jacopovalanzano](/maintainers/jacopovalanzano)

---

Top Contributors

[![jacopovalanzano](https://avatars.githubusercontent.com/u/85193021?v=4)](https://github.com/jacopovalanzano "jacopovalanzano (18 commits)")

---

Tags

captchaphprecaptchaAuthenticationrecaptchaspamcaptchabot

### Embed Badge

![Health badge](/badges/jacopovalanzano-php-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/jacopovalanzano-php-captcha/health.svg)](https://phpackages.com/packages/jacopovalanzano-php-captcha)
```

###  Alternatives

[google/recaptcha

Client library for reCAPTCHA, a free service that protects websites from spam and abuse.

3.6k94.0M259](/packages/google-recaptcha)[anhskohbo/no-captcha

No CAPTCHA reCAPTCHA For Laravel.

1.8k9.0M34](/packages/anhskohbo-no-captcha)[albertcht/invisible-recaptcha

Invisible reCAPTCHA For Laravel.

6071.6M6](/packages/albertcht-invisible-recaptcha)[josiasmontag/laravel-recaptchav3

Recaptcha V3 for Laravel package

2701.9M2](/packages/josiasmontag-laravel-recaptchav3)[arcanedev/no-captcha

No CAPTCHA (new Google reCAPTCHA) with Laravel support

369742.5k6](/packages/arcanedev-no-captcha)[buzz/laravel-google-captcha

Google captcha for Laravel

2101.1M2](/packages/buzz-laravel-google-captcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
