Skip to content
netherphpPublic

About

A captcha that like all the others probably will not stop anything AI enabled.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

NetherPHP: Captcha

Packagist Build Status codecov

A locally produced Captcha.

Features

  • Generates captcha image.
  • Configurable code length.
  • Configurable time sensitivity.
  • Simple API for validating token and codes.

Requirements

  • PHP 8.5+
  • PHP Imagick

Install

$ composer require netherphp/captcha

Usage

Get a new fully rendered captcha using the ::Fresh() factory method. Get a new captcha where you can set settings before rendering with the ::New() factory method.

<?php

// prepare new captcha that is fully rendered.

$Cap = Nether\Captcha::Fresh();

// prepare captcha that can be configured before rendering.

$Cap = Nether\Captcha::New();
$Cap->SetTimeToExpire(60);
$Cap->Generate();

?>

Render the image in the form you want to protect with the captcha.

<div>
	<div>
		<img src="<?php echo $Cap->GetImageEncoded() ?>" title="Captcha Image" />
	</div>
	<div>
		<p>Enter code from above image.</p>
		<input type="text" name="<?php echo $Cap->GetCodeFieldName() ?>" />
		<input type="hidden" name="<?php echo $Cap->GetTokenFieldName() ?>" value="<?php echo $Cap->GetTokenFieldValue() ?>" />
	</div>
</div>

Use the ::ValidateFromInput() method to automatically find the captcha fields from a dump of input with considerations handling the raw input automatically.

$CaptchaOK = Nether\Captcha::ValidateFromInput($_POST);

if(!$CaptchaOK) {
	echo 'failed to validate captcha.';
	return;
}

Use the ::Validate() method to manually validate known token and codes.

$CaptchaOK = Nether\Captcha::Validate(
	$_POST['nether-captcha-token'],
	$_POST['nether-captcha-code']
);

if(!$CaptchaOK) {
	echo 'failed to validate captcha.';
	return;
}

Todo

  • Include front end templating.

About

A captcha that like all the others probably will not stop anything AI enabled.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages