## **第一步下载验证码** ~~~ composer require topthink/think-captcha ~~~ 第二部复制 vendor/tpthink/think-captcha目录下面src/config.php 到 conig里面改名为 captcha方便配置 ![](https://img.kancloud.cn/0c/f1/0cf1f038c5176170ecce6beb910b7169_422x748.png) ## **第三部:代码引用** ## 前端 ~~~ <div><img src="{:url('/admin/Verify/index')}" alt="captcha" class="admin-captcha" onClick="this.src='{:url('/admin/Verify/index')}?'+Math.random();"/> </div> ~~~ ## **后台** ~~~ namespace app\admin\controller; use think\captcha\facade\Captcha; class Verify { public function index(){ return Captcha::create("verify"); } } ~~~ ## 配置文件表: ~~~ <?php // +---------------------------------------------------------------------- // | Captcha配置文件 // +---------------------------------------------------------------------- return [ //验证码位数 'length' => 5, // 验证码字符集合 'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY', // 验证码过期时间 'expire' => 1800, // 是否使用中文验证码 'useZh' => false, // 是否使用算术验证码 'math' => false, // 是否使用背景图 'useImgBg' => false, //验证码字符大小 'fontSize' => 25, // 是否使用混淆曲线 'useCurve' => true, //是否添加杂点 'useNoise' => true, // 验证码字体 不设置则随机 'fontttf' => '', //背景颜色 'bg' => [243, 251, 254], // 验证码图片高度 'imageH' => 0, // 验证码图片宽度 'imageW' => 0, // 添加额外的验证码设置 'verify' => [ 'length'=>4, 'imageH' => 38, 'imageW' => 95, //验证码字符大小 'fontSize' => 14, ], ]; ~~~ # 第二种模式验证码适合异步提交 ``` http://packagist.p2hp.com/packages/edward1108/edward-captcha ```