<?php /** * Created by PhpStorm. * User: admin.Li * Date: 2018/5/16 * Time: 17:17 */ namespace appindexcontroller; use thinkController; class Yzm extends Controller { public function index(){ return $this->fetch(); } //验证码的处理方法 public function check(){ $captcha=input('post.code'); //判断验证码是否正确 if(!captcha_check($captcha)){ //验证失败 echo 'error'; }else{ echo 'ok'; } } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>验证码测试</title> </head> <body> <form action="{:url('check')}" method="post"> <p> 验证码:<!--{:captcha_img()}--> <img src="{:captcha_src()}" alt="captcha" /> </p> <p> 请输入验证码: <input type="text" name="code" id=""> </p> <p> <input type="submit" value="提交"> </p> </form> </body> </html>
验证码相关配置
//具体的配置参考扩展类Captcha.php 'captcha' =>[ //验证码的字符集和 'codeSet'=>'123', // 使用中文验证码 'useZh' => true, // 中文验证码字符串 'zhSet' => '大家好才是真的好', // 验证码位数 'length' => 4, ],