ভেরিফিকেশন কোড কম্পোনেন্ট

প্রকল্পের ঠিকানা https://github.com/webman-php/captcha

ইনস্টলেশন

composer require webman/captcha

ব্যবহার

ফাইল তৈরি করুন app/controller/LoginController.php

<?php
namespace app\controller;

use support\Request;
use Webman\Captcha\CaptchaBuilder;

class LoginController
{
    /**
     * পরীক্ষা পৃষ্ঠা
     */
    public function index(Request $request)
    {
        return view('login/index');
    }

    /**
     * ভেরিফিকেশন কোডের চিত্র আউটপুট করুন
     */
    public function captcha(Request $request)
    {
        // ভেরিফিকেশন কোড শ্রেণী প্রারম্ভ করুন
        $builder = new CaptchaBuilder;
        // ভেরিফিকেশন কোড তৈরি করুন
        $builder->build();
        // ভেরিফিকেশন কোডের মানটি সেশনে সংরক্ষণ করুন
        $request->session()->set('captcha', strtolower($builder->getPhrase()));
        // ভেরিফিকেশন কোডের ছবির বাইনারি ডেটা পান
        $img_content = $builder->get();
        // ভেরিফিকেশন কোডের বাইনারি ডেটা আউটপুট করুন
        return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
    }

    /**
     * ভেরিফিকেশন কোড পরীক্ষা করুন
     */
    public function check(Request $request)
    {
        // পোস্ট অনুরোধের মধ্যে captcha ক্ষেত্রটি পান
        $captcha = $request->post('captcha');
        // সেশনের মধ্যে captcha মানের সাথে তুলনা করুন
        if (strtolower($captcha) !== $request->session()->get('captcha')) {
            return json(['code' => 400, 'msg' => 'ইনপুট করা ভেরিফিকেশন কোড সঠিক নয়']);
        }
        return json(['code' => 0, 'msg' => 'ঠিক আছে']);
    }

}

টেমপ্লেট ফাইল তৈরি করুন app/view/login/index.html

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>ভেরিফিকেশন কোড পরীক্ষা</title>  
</head>
<body>
    <form method="post" action="/login/check">
       <img src="/login/captcha" /><br>
        <input type="text" name="captcha" />
        <input type="submit" value="জমা দিন" />
    </form>
</body>
</html>

পৃষ্ঠায় যান http://127.0.0.1:8787/login ইন্টারফেসটি এর মতো হবে:

সাধারণ প্যারামিটার সেটিংস

    /**
     * ভেরিফিকেশন কোডের চিত্র আউটপুট করুন
     */
    public function captcha(Request $request)
    {
        $builder = new PhraseBuilder(4, 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ');
        $captcha = new Captcha(null, $builder);
        $captcha->build();
        $request->session()->set('join', strtolower($captcha->getPhrase()));
        $img_content = $captcha->get();
        return response($img_content, 200, ['Content-Type' => 'image/jpeg']);
    }

আরও ইন্টারফেস এবং প্যারামিটারের জন্য রেফারেন্স https://github.com/webman-php/captcha