index.html
<!DOCTYPE html>
<html lang="en">
<head>
<me
<ti
<css href="public/Css/st
<sc
</head>
<body>
<h1>验证码验证</h1>
<form action="__URL__/check" method="post">
<p><label for="vcode">验证码:</label><input type="text" id="vcode" name="vcode"><div><img on
<p><input type="submit" value="验证"></p>
</form>
<sc
$(function () {
$("img").click()
}) //页面加载自动执行一次点击事件
</sc
</body>
</html>
index.php
<?php
namespace app\index\controller;//声明命名空间
session_start();
use think\Controller;//引入系统控制器类
class Index extends Controller
{
public function index(){
return view(); 显示视图
return $this->fetch(2); //生成验证码
}
public function check(){ // 验证码处理方法
/* $vcode=$_POST['vcode'];*/
$vcode=input("post.vcode",1);//获取表单里验证码的值
if(captcha_check($vcode)){ // 判断验证码是否正确
$this->success("验证码正确","index/index",3);
}else{
$this->success("验证码错误","index/index",3);
}
}
}
