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
)){
//验证失败
};
也可以自定义验证码用法
原文:https://www.cnblogs.com/lhc1999/p/14358648.html