我使用的thinkphp框架是带有think-captcha的,没有的使用composer在框架根目录下执行(5.0版本)(5.1版本框架使用2.0)
composer require topthink/think-captcha=1.*
装完,在app的控制器写出方法以及对应的view文件,
demo.php
//访问到模板
public function testCaptcha(){
return $this->fetch();
}
//表单提交过来的验证码验证
public function testCaptchaResult(){
$code = input('captcha');
if (!captcha_check($code)){
echo '验证未通过';
}else{
echo '验证通过';
}
}
对应的test_captcha.html文件
<form action="/index/demo/testCaptchaResult" method="post">
<div>{:captcha_img()}</div>
<input name="captcha">
<input type="submit" value="提交">