iktbd/captcha-image

Make your security captcha image

2.00 2022-07-01 13:49 UTC

This package is auto-updated.

Last update: 2024-08-29 06:02:00 UTC


README

Make your security captcha image

alt text

Features

  • Make your own captcha image and use
  • Make your system safe
  • More!

Installation & loading

captcha-image is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install captcha-image. Just add this line to your composer.json file:

"iktbd/captcha-image": "^2.00"

or run

composer require iktbd/captcha-image

Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of captcha-image.

Use the captcha-image

Create captcher

<?php
use Iktbd\CaptchaImage\Captcha;

//Set your password as your wish
$password='djhfhdfywh53477';

//Create new captcha
$src_string=Captcha::create($password);

Use the $src_string in the html image

<form id="" action="#" method="post">
<img src="{{$src_string}}" height="50" width="250">
<input type="text" name="captcha_text" value="">
<input type="submit" value="Submit">
</form>

Varify Captcha data

<?php
use Iktbd\CaptchaImage\Captcha;


//Set your same password
$password='djhfhdfywh53477';

//Get the input value from the form submit
$text=$_POST['captcha_text'];

//Check submitted captcha data
$result=Captcha::verify($password,$text);

if($result==true)
{
    echo 'Captcha is correct';
}
else
{
    echo 'Captcha is wrong';
}

Note

  • If you want to create a new captcha and verify your old submitted captcha then verify your old submitted captcha first then create new captcha
  • You should remember that every new captcha generate a new session and delete the old session.
  • So, if you create a new captcha than if you verify the old submitted captcha then it will return false. Because the old captcha data already deleted when you create a new captcha

Error Note

  • Be sure that your PHP GD extension is enable else you will get an error.
  • If your PHP GD extension is not enable, then enable the GD extension.
  • To enable PHP GD extension, go to your cpanel then go to PHP version selector then tick the GD check box and save it.
  • Or check if in your php.ini file has the following line ;extension=gd
  • If exists, change it to extension=gd
  • If not found, Add this extension=gd to your php.ini