TP5验证码

TP5无自带验证码,需要下载,以下是通过composer安装的方式(直接复制到指定位置也可以)

1.打开电脑CMD命令窗口,然后进入项目\vendor\topthink目录下,就可以运行命令

composer require topthink/think-captcha

2.控制器和视图,配置
配置:application/config.php
TP5验证码
控制器不需要写输出方法,只需要写验证方法

public function check($code = ' ')
    	{
        $captcha = new \think\captcha\Captcha();
        if (!$captcha->check($code)) {
            $this->error('验证码错误');
        } else {
            $this->success('验证码正确');
        }
   	 } 

视图

	{:captcha_img()}