PHP code example of ganlvtech / think-kcaptcha

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

    

ganlvtech / think-kcaptcha example snippets


$this->validate($data,[
    'captcha|验证码'=>'

if(!captcha_check($captcha)){
    //验证失败
};

'captcha' => [
    // 验证码加密密钥
    'seKey' => 'ThinkPHP.CN',
    // 验证码过期时间(s)
    'expire' => 1800,
    // 验证成功后是否重置
    'reset' => true,
    // 验证码字符集合
    'codeSet' => '23456789abcdegikpqsvxyz',
    // 验证码图片宽度
    'imageW' => 160,
    // 验证码图片高度
    'imageH' => 80,
    // 验证码位数
    'length' => mt_rand(5, 7),
    // 【KCAPTCHA专用】KCAPTCHA字体图片所在目录
    'fontsdir' => 'fonts',
    // 【KCAPTCHA专用】KCAPTCHA字体图片中的字符表
    'alphabet' => "0123456789abcdefghijklmnopqrstuvwxyz",
    // 【KCAPTCHA专用】波动幅度
    'fluctuation_amplitude' => 8,
    // 【KCAPTCHA专用】白色杂点密度(0表示没有)
    'white_noise_density' => 1 / 6,
    // 【KCAPTCHA专用】黑色杂点密度(0表示没有)
    'black_noise_density' => 1 / 30,
    // 【KCAPTCHA专用】字符是否强制粘连
    'no_spaces' => true,
    // 【KCAPTCHA专用】下方是否显示credits(开启会在高度方向额外增加12px)(注:credit表示对原作者及其他有贡献者的谢启、及鸣谢者姓名)
    'show_credits' => true,
    // 【KCAPTCHA专用】credits内容(如果为空,则显示HTTP_HOST)
    'credits' => 'www.captcha.ru',
    // 【KCAPTCHA专用】验证码文字颜色
    'foreground_color' => [mt_rand(0, 80), mt_rand(0, 80), mt_rand(0, 80)],
    // 【KCAPTCHA专用】验证码背景颜色
    'background_color' => [mt_rand(220, 255), mt_rand(220, 255), mt_rand(220, 255)],
    // 【KCAPTCHA专用】输出JPEG是压缩质量
    'jpeg_quality' => 75,
],