Download the PHP package websk/php-captcha without Composer
On this page you can find all versions of the php package websk/php-captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download websk/php-captcha
More information about websk/php-captcha
Files in websk/php-captcha
Package php-captcha
Short Description Captcha generator and Slim route handlers
License MIT
Informations about the package php-captcha
WebSK PHP Captcha
websk/php-captcha generates PNG CAPTCHA images and provides Slim 4 route
handlers for generating and validating them.
Requirements
- PHP 8.3 or later, including PHP 8.5
- GD with FreeType support
- Mbstring
- PHP sessions
- Slim 4
Installation
Install the package with Composer:
The package is available on Packagist.
Slim integration
Register the CAPTCHA routes on an existing Slim application:
This adds two named GET routes:
| Route | Name | Response |
|---|---|---|
/captcha/generate |
captcha:generate |
image/png |
/captcha/check_ajax |
captcha:check_ajax |
JSON true or false |
Display the generated image and use the captcha field for the entered code:
The validation route accepts the code from parsed request data or the query string:
The expected value is stored in the server-side PHP session and is removed
after a non-empty validation attempt. Generate a new image before retrying.
When no session is active, the package starts one with strict mode, an
HttpOnly cookie, and SameSite=Lax by default. Existing session settings are
used when the application starts the session first.
Request handlers pass their PSR-7 request directly to Captcha::check(). Code
outside a handler can do the same:
Demo
Run the bundled Slim application:
Then open http://localhost:8000. The root route redirects to the generated CAPTCHA image.
Development
Run syntax checks, PHPUnit, and PHPStan together:
The individual commands are also available:
Upgrade from 2.x
Version 3.0 stores the expected CAPTCHA value in the server-side session. The
2.x client-side CAPTCHA cookie is no longer trusted. Applications must have PHP
sessions available and should pass the current PSR-7 request to
Captcha::check().
License
This project is licensed under the MIT License.
All versions of php-captcha with dependencies
ext-mbstring Version *
ext-gd Version *
ext-session Version *
slim/slim Version ^4.15
websk/php-slim Version 2.4.*
websk/php-utils Version 3.0.*