验证码验证

浏览:771 发布日期:2018/04/19 分类:用法示例 关键字: 验证码
简单的验证码验证
index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<title>验证码验证</title>
<css href="public/Css/style1.css" />
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

</head>
<body>

<h1>验证码验证</h1>
<form action="__URL__/check" method="post">
<p><label for="vcode">验证码:</label><input type="text" id="vcode" name="vcode"><div><img onclick="this.src='{:captcha_src()}'" src="{:captcha_src()}"/></div></p> <!--引用验证码图片-->
<p><input type="submit" value="验证"></p>
</form>
<script>

$(function () {
$("img").click()
}) //页面加载自动执行一次点击事件

</script>
</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);
}

}


}
评论( 相关
后面还有条评论,点击查看>>