PHP code example of fractal512 / captcha

1. Go to this page and download the library: Download fractal512/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/ */

    

fractal512 / captcha example snippets


    'providers' => [
        // ...
        'Fractal512\Captcha\CaptchaServiceProvider',
    ]

    'providers' => [
        // ...
        Fractal512\Captcha\CaptchaServiceProvider::class,
    ]

    'aliases' => [
        // ...
        'Captcha' => 'Fractal512\Captcha\Facades\Captcha',
    ]

    'aliases' => [
        // ...
        'Captcha' => Fractal512\Captcha\Facades\Captcha::class,
    ]

return [
    'characters' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
    'expire' => 300,
    'attempts' => 10,
    'default' => [],
    'numbers' => [
        'characters' => '0123456789'
    ],
    'letters' => [
        'characters' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ],
    'uppercase' => [
        'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ],
    'lowercase' => [
        'characters' => 'abcdefghijklmnopqrstuvwxyz'
    ]
];


    // base_path() . "/routes/web.php"
    Route::any('captcha-example', function() {
        if (request()->getMethod() == 'POST') {
            $rules = ['captcha' => ' failed!</p>';
            } else {
                echo '<p style="color: #00ff00;">Verification passed!</p>';
            }
        }
    
        $form = '<form method="post" action="">';
        $form .= '<input type="hidden" name="_token" value="' . csrf_token() . '">';
        $form .= '<p>';
        $form .= captcha_img('default', ['id' => 'captcha-img']);
        $form .= '<a href="#" onclick="document.getElementById(\'captcha-img\').src = \'/captcha/default?\' + Date.now()">Refresh</a>';
        $form .= '</p>';
        $form .= '<p><input type="text" name="captcha"></p>';
        $form .= '<p><button type="submit" name="check">Check captcha</button></p>';
        $form .= '</form>';
        return $form;
    });

captcha();

Captcha::create();

captcha_src();

Captcha::src('default');

captcha_img();

Captcha::img();

captcha_img('numbers');

Captcha::img('uppercase');
shell script
$ php artisan vendor:publish --provider="Fractal512\Captcha\CaptchaServiceProvider" --tag="config"
shell script
$ php artisan vendor:publish