Skip to content

zerosdev/PHP-Captcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Captcha Generator

To use this library, make sure you are using PHP 5.6 or latest

AVAILABLE METHOD

image()

Used to get base64 image of generated captcha

id()

Used to get captcha generation id, this id is used to validate the captcha input from client/user

chars()

Set the character list that will be used to generate captcha code

length()

Define the captcha code length

size()

Set the width and height of captcha image

generate()

Generate captcha

form_field()

Generate html hidden input of Captcha ID

html_image()

Generate html image tag

validate()

Validate captcha from user input

EXAMPLE USAGE

HTML Form


<?php

require '/path/to/src/Captcha.php';

$captcha = new ZerosDev\Captcha();
$generate = $captcha->length(6)->chars('ABCDEFGHIJKLMNOPQRSTUVWXYZ')->size(170, 50)->generate();

?>

<form>
  <input type="hidden" name="captcha_id" value="<?php echo $generate->id(); ?>">
  <img src="<?php echo $generate->image(); ?>" />
  <label for="captcha">Captcha Code:</label>
  <br/>
  <input type="text" name="captcha" required>
  <br/><br/>
  <input type="submit" value="SUBMIT">
</form>

Validation


<?php

require '/path/to/src/Captcha.php';

$captcha = new ZerosDev\Captcha();

if( $captcha->validate($_POST['captcha_id'], $_POST['captcha']) )
{
    echo 'Valid!';
}
else
{
    echo 'Invalid';
}

?>

About

Captcha Generator for PHP 5.6+

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages