PHP code example of mohsenfathipour / captcha-generator

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

    

mohsenfathipour / captcha-generator example snippets


return [
    'width' => 120, // Default width of the CAPTCHA image
    'height' => 35, // Default height of the CAPTCHA image
    'characters' => 'ABCDEFGHJKLMNPQRTWZ234679', // Characters used in CAPTCHA (Avoids similar characters)
    'bg_color' => 'F0F0F0', // Default background color (hex format)
];

use Illuminate\Support\Facades\Session;

$request->validate([
    'captcha' => function ($attribute, $value, $fail) {
        if ($value !== Session::get('captcha.form1')) {
            $fail('The captcha code is incorrect.');
        }
    },
]);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use MohsenFathipour\CaptchaGenerator\Facades\Captcha;

class MyController extends Controller
{
    public function showCaptchaForm()
    {
        return view('myform');
    }

    public function validateCaptcha(Request $request)
    {
        $request->validate([
            'captcha' => function ($attribute, $value, $fail) {
                if ($value !== Session::get('captcha.form1')) {
                    $fail('The captcha code is incorrect.');
                }
            },
        ]);

        // Your form submission logic here...
    }
}
bash
php artisan vendor:publish --provider="MohsenFathipour\CaptchaGenerator\CaptchaServiceProvider" --tag="config"