Captcha

Creates a captcha image. The image can be written into the response (the image will be responded immediately) or to a file. The string in the image will be stored into the session. The "checkWord()" method checks if a word matches the previously stored value. Only one captcha may be created for a session. The Artaengine widget and form generator classes use this class to generate captcha. This class was created based on the SimplCaptcha library (http://code.google.com/p/cool-php-captcha).
Source
Captcha.php
Depends on
Utils , Arta
Since
1.4.0

Constants

SESSION_KEY = 'captcha-word'

Session key to set captcha word to.

Properties

fonts = array

$obj->fonts = array(
        array('spacing' => -3, 'min' => 17, 'max' => 25, 'file' => 'AntykwaBold.ttf'),
        array('spacing' => -2, 'min' => 14, 'max' => 25, 'file' => 'Ding-DongDaddyO.ttf'),
        array('spacing' => -2, 'min' => 27, 'max' => 30, 'file' => 'Duality.ttf'),
        array('spacing' => -2, 'min' => 20, 'max' => 27, 'file' => 'Jura.ttf'),
        array('spacing' =>-1.5,'min' => 25, 'max' => 28, 'file' => 'StayPuft.ttf'),
        array('spacing' => -1, 'min' => 20, 'max' => 23, 'file' => 'VeraSansBold.ttf'),
    )

TTF fonts to be used for drawing the captcha word.

Static Methods

checkWord

bool Captcha::checkWord(string word)

Check if the passed word matches the captcha word which was stored in session.

Arguments

    word (string)
    the word to be checked against session

Returns

bool
true=captcha words matched

Methods

__construct

Captcha $obj = new Captcha(array configs)

Constructor.

Arguments

    configs (array)
    the captcha configs.
    {
        array  word-len     : [4, 7]
            min and max length for the captcha random word,
        int    width        : 230
            image width,
        int    height       : 70
            image height,
        string image-format : jpeg
            image format 'jpeg' or 'png',
        bool   blur         : true
            blur the image if possible,
        int    hline-width  : 1
            draw a line with this width on the text
            false or null = do not draw line,
        int    max-rotation : 1
            amount of text rotation,
        array  back-color   : [255, 255, 255]
            image back-color [r, g, b],
        array  shadow-color : null
            image back-color [r, g, b] or null=no shadow,
        array  text-color   : colors
            a selection of colors for the captcha text [[r, g, b],]
        array  wave         :
            {
                int y-period    : 19,
                int y-amplitude : 9,
                int x-period    : 9,
                int x-amplitude : 4,
            }
    }
    

Returns

void

write

void $obj->write(string filepath=null)

Write a captcha image to response or to a file. The random text generated and drawn in the image will be stored in the session.

Arguments

    filepath=null (string)
    null=write the image to response otherwise write to the filepath

Returns

void