PHP code example of mobicms / captcha

1. Go to this page and download the library: Download mobicms/captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mobicms / captcha example snippets



$captcha = new Mobicms\Captcha\Image();
$_SESSION['code'] = $captcha->getCode();

$result = filter_input(INPUT_POST, 'code');
$session = filter_input(INPUT_SESSION, 'code');

if ($result !== null && $session !== null) {
    if (strtolower($result) == strtolower($session)) {
        // CAPTCHA code is correct
    } else {
        // CAPTCHA code is incorrect, show an error to the user
    }
}

$captcha = new Mobicms\Captcha\Image();

// Set the image width (default: 190)
$captcha->imageWidth = 250;
// Set the image height (default: 90)
$captcha->imageHeight = 100;

$captcha = new Mobicms\Captcha\Image();

$captcha->fontFolders = array_merge(
    // Using built-in fonts 
    $captcha->fontFolders,

    // Specifying your font folders
    ['folder1', 'folder2']
);

$captcha = new Mobicms\Captcha\Image();

$adjust = [
    // Specify the name of the font file
    'myfont1.ttf' => [
        // Specify the relative font size.
        // It will be summarized with the default size specified in the $defaultFontSize property
        // In this case, the font will be used: 30+16=46
        'size' => 16, // Optional
        // Forcing the use of only lowercase characters of the specified font
        'case' => \Mobicms\Captcha\Image::FONT_CASE_LOWER, // Optional
    ],

    'myfont2.ttf' => [
        // Forcing the use of only uppercase characters of the specified font
        'case' => \Mobicms\Captcha\Image::FONT_CASE_UPPER,
    ],

    'myfont3.ttf' => [
        // Font size will be decreased by 8
        'size' => -8,
    ],

    'myfont4.ttf' => [
        // Font size will be increased by 4
        'size' => 4,
    ],
];

$captcha->fontsTune = array_merge($captcha->fontsTune, $adjust);

$code = 'FooBar';
$captcha = new Mobicms\Captcha\Image($code);