PHP code example of shetabit / captcha

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

    

shetabit / captcha example snippets


# In your providers array.
'providers' => [
    ...
    Shetabit\Captcha\Provider\CaptchaServiceProvider::class,
],

# In your aliases array.
'aliases' => [
    ...
    'Payment' => Shetabit\Captcha\Facade\Captcha::class,
],

// Eg. if you want to use simple. (simple is the driver's name)
'default' => 'simple',

'drivers' => [
    'simple' => [
        'middleware' => ['web'], // middleware
        'route' => 'captcha', // route name
        'characters' => 'ABCDEFGHIKJLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789',
        'width'  => 230,
        'height' => 70,
        'foregroundColors' => ['2980b9','2E9FFF','FF1166','000000','22EE99'],
        'backgroundColor' => '#FFF',
        'letterSpacing' => 6,
        'fontFamily' => resource_path('views/vendor/captchaSimpleDriver/assets/fonts/DroidSerif.ttf'),
        'fontSize' => 30,
        'length' => [4, 6],
        'scratches' => [5, 8],
        'sensitive' => false,
        'sessionKey' => 'captcha',
    ],
    ...
]

<form>
...

{!! captcha() !!}

...
</form>

...

$request->validate([
    'email' => ''captcha' => '

'drivers' => [
    'simple' => [...],
    'my_driver' => [
        ... # Your Config Params here.
    ]
]

namespace App\Packages\CaptchaDriver;

use Illuminate\Support\ServiceProvider;
use Shetabit\Captcha\Abstracts\Driver;

class MyDriver extends Driver
{
    protected $serviceProvider;

    /**
     * Driver settings.
     *
     * @var object
     */
    protected $settings;

    public function __construct(ServiceProvider $serviceProvider, $settings)
    {
        $this->serviceProvider = $serviceProvider;
        $this->settings = (object) $settings;
    }
    
    /**
        you must write your captcha generation 
        logic in the below method.
    **/
    public function generate()
    {
        ...
    
        // create captcha view and return it
        return View::make('yourCustomDriverView');
    }

    /**
        you must write your captcha verification
        logic in the below method.
    **/
    public function verify($token = null)
    {
        ...
    
        $storedToken = ...

        if (empty($this->settings->sensitive)) {
            $storedToken = mb_strtolower($storedToken);
            $token = mb_strtolower($token);
        }

        return $token == $storedToken;
    }
    
}

'map' => [
    ...
    'my_driver' => App\Packages\CaptchaDriver\MyDriver::class,
]