2017 © Pedro PelĂĄez
 

captcha captcha

Captcha generator

image

gregwar/captcha

Captcha generator

  • Tuesday, April 24, 2018
  • by Gregwar
  • Repository
  • 43 Watchers
  • 850 Stars
  • 1,540,350 Installations
  • PHP
  • 163 Dependents
  • 5 Suggesters
  • 174 Forks
  • 11 Open issues
  • 22 Versions
  • 7 % Grown

The README.md

Captcha

Captchas examples paypal, (*1)

Installation

With composer :, (*2)

``` json { ... "require": { "gregwar/captcha": "1.*" } }, (*3)


Usage ===== You can create a captcha with the `CaptchaBuilder` : ```php build(); ``` You can then save it to a file : ```php save('out.jpg'); ``` Or output it directly : ```php output(); ``` Or inline it directly in the HTML page: ```php

You'll be able to get the code and compare it with a user input :, (*4)

<?php

// Example: storing the phrase in the session to test for the user 
// input later
$_SESSION['phrase'] = $builder->getPhrase();

You can compare the phrase with user input:, (*5)

if($builder->testPhrase($userInput)) {
    // instructions if user phrase is good
}
else {
    // user phrase is wrong
}

API

You can use theses functions :, (*6)

  • __construct($phrase = null), constructs the builder with the given phrase, if the phrase is null, a random one will be generated
  • getPhrase(), allow you to get the phrase contents
  • setDistortion($distortion), enable or disable the distortion, call it before build()
  • isOCRReadable(), returns true if the OCR can be read using the ocrad software, you'll need to have shell_exec enabled, imagemagick and ocrad installed
  • buildAgainstOCR($width = 150, $height = 40, $font = null), builds a code until it is not readable by ocrad
  • build($width = 150, $height = 40, $font = null), builds a code with the given $width, $height and $font. By default, a random font will be used from the library
  • save($filename, $quality = 80), saves the captcha into a jpeg in the $filename, with the given quality
  • get($quality = 80), returns the jpeg data
  • output($quality = 80), directly outputs the jpeg code to a browser
  • setBackgroundColor($r, $g, $b), sets the background color to force it (this will disable many effects and is not recommended)
  • setBackgroundImages(array($imagepath1, $imagePath2)), Sets custom background images to be used as captcha background. It is recommended to disable image effects when passing custom images for background (ignore_all_effects). A random image is selected from the list passed, the full paths to the image files must be passed.
  • setInterpolation($interpolate), enable or disable the interpolation (enabled by default), disabling it will be quicker but the images will look uglier
  • setIgnoreAllEffects($ignoreAllEffects), disable all effects on the captcha image. Recommended to use when passing custom background images for the captcha.
  • testPhrase($phrase), returns true if the given phrase is good
  • setMaxBehindLines($lines), sets the maximum number of lines behind the code
  • setMaxFrontLines($lines), sets the maximum number of lines on the front of the code

If you want to change the number of character, you can call the phrase builder directly using extra parameters:, (*7)

use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;

// Will build phrases of 3 characters
$phraseBuilder = new PhraseBuilder(4);

// Will build phrases of 5 characters, only digits
$phraseBuilder = new PhraseBuilder(5, '0123456789');

// Pass it as first argument of CaptchaBuilder, passing it the phrase
// builder
$captcha = new CaptchaBuilder(null, $phraseBuilder);

You can also pass directly the wanted phrase to the builder:, (*8)

// Building a Captcha with the "hello" phrase
$captcha = new CaptchaBuilder('hello');

Complete example

If you want to see an example you can have a look at the demo/form.php, which uses demo/session.php to render a captcha and check it after the submission, (*9)

Symfony Bundle

You can have a look at the following repository to enjoy the Symfony 2 bundle packaging this captcha generator : https://github.com/Gregwar/CaptchaBundle, (*10)

Yii2 Extension

You can use the following extension for integrating with Yii2 Framework : https://github.com/juliardi/yii2-captcha, (*11)

License

This library is under MIT license, have a look to the LICENSE file, (*12)

The Versions

24/04 2018

dev-master

9999999-dev https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

 

The Development Requires

bot captcha spam

24/04 2018

v1.1.6

1.1.6.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

 

The Development Requires

bot captcha spam

30/12 2017

v1.1.5

1.1.5.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

 

The Development Requires

bot captcha spam

01/12 2017

v1.1.4

1.1.4.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

 

The Development Requires

bot captcha spam

27/09 2017

v1.1.3

1.1.3.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

19/04 2017

v1.1.2

1.1.2.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

11/09 2015

v1.0.13

1.0.13.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

11/09 2015

v1.1.1

1.1.1.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

13/05 2015

v1.1

1.1.0.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

03/01 2015

v1.0.12

1.0.12.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

19/03 2014

v1.0.11

1.0.11.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

27/11 2013

v1.0.10

1.0.10.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

29/09 2013

v1.0.9

1.0.9.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

14/08 2013

v1.0.8

1.0.8.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

19/06 2013

v1.0.7

1.0.7.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

07/05 2013

v1.0.6

1.0.6.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

24/04 2013

v1.0.5

1.0.5.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

22/04 2013

v1.0.4

1.0.4.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

17/03 2013

v1.0.2

1.0.2.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

17/03 2013

v1.0.3

1.0.3.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

21/01 2013

v1.0.1

1.0.1.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam

05/01 2013

v1.0

1.0.0.0 https://github.com/Gregwar/Captcha

Captcha generator

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-gd *

 

bot captcha spam