Skip to content

jootamas/php-captcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Full customizable captcha in PHP

Usage

  1. add captcha.class.php to your system
  2. search any font in TTF or OTF, and set it in the Captcha class
  3. set captcha parameters as you wish, based on your site design

Quick example:

<?php
session_start();
include('captcha.class.php');

define(CAPTCHA_TTF, './myfont.ttf');

$captcha = new Captcha();

/* Optional: overwrite default parameters */
$captcha->str_length = 4;

if($_POST){
 if($captcha->check($_POST['captcha_input'])){
  /* success, do something */
 } else {
  /* error, do something */
 }
}
?>
<form method="post">
<input type="text" name="name" />
<input type="text" name="email" />
<textarea name="message"></textarea>
...
<img src="<?php echo $captcha->get(); ?>" />
...
<input type="text" name="captcha_input" maxlength="4" />
</form>

PREFIX: If you use more captcha on one page, you can set prefix, e.g. contact, cart, etc.

Examples

Basic:

Picture

Shadows:

Picture

Push letters vertically up or down:

Picture

Rotate letters:

Picture

Draw random lines on the background:

Picture

And any sizes:

Picture

Picture

Picture

Picture

Patterns:

Picture

Picture

Changelog

18/12/2016 - v1.0

init

04/09/2017 - v2.0

  • some fixes
  • simplification: remove captcha_image.php, the captcha image generated in the Captcha class
  • use pattern
  • replace the attributes of check() function

26/10/2017 - v2.1

  • quick fix at patterns
  • error handling: if don't set font file print error message and exit
  • remove reconfigure() function, because it's unnecessary

Notes

Note 1: session_start() required!

Note 2: minimum PHP version: 4.0.6

Font: https://fonts.google.com/specimen/Titillium+Web

Patterns: http://bgrepeat.com


All suggestions will be welcome. :)

About

Fully customizable captcha in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages