topthink/think-captcha 是 ThinkPHP 官方团队开发的适用于 TP 各版本的验证码扩展包
该验证码扩展包目前有三个主版本: 1.x、2.x、3.x,分别适用于 TP5.0、TP5.1、TP6.0
packagist: https://packagist.org/packages/topthink/think-captcha
// TP5.0
以 TP6.0 为例(当前最新版就是3.*,不需要指定版本号)
composer require topthink/think-captcha
安装命令执行后会在全局配置目录(config)下生成 captcha.php 验证码全局配置文件 config/captcha.php
<img src="{:captcha_src()}" onclick="this.src = '{:captcha_src()}' + '?v=' + Math.random()" style="cursor: pointer;" />
return \think\captcha\facade\Captcha::create('login');
if (!captcha_check($captcha)) {