TP5 验证码的设置与使用
首先使用Composer安装think-captcha扩展包:
composer require topthink/think-captcha=1.*
模版内验证码的显示
<div>{:captcha_img()}</div> <div><img src="{:captcha_src()}" alt="captcha" onclik="this.src='{:captcha_src()}'" /></div>
内置验证功能,添加captcha验证规则即可
$this->validate($data,[ 'captcha|验证码'=>'require|captcha' ]); //或者手动验证 if(!captcha_check($captcha)){ //验证失败 };