thinkphp 验证码功能的实现与验证

浏览:8027 发布日期:2018/04/19 分类:用法示例
thinkphp 验证码功能的实现与验证
[index.html[url][/url]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="__PUBLIC__/js/jquery-1.6.2.min.js"></script>
</script>
<script>
$(function(){
$('img').click(function(){
$('img').attr('src',"__URL__/vcode/random/"+Math.random());
});
});
</script>
</head>
<body>
<form method="post" action="__URL__/check">
用户名<input type="text" name="username"><br>
密码<input type="password" name="password"><br>
验证码<input type="text" name="code"><img src="__URL__/vcode"><br>
<input type="submit" name="">
</form>
</body>
</html>




IndexController.class.php



<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$this->display();
}
public function vcode(){
$Verify = new \Think\Verify();
$Verify->entry(1);
}
public function check(){
header("Content-type: text/html; charset=utf-8");
$code=I('code');
$verify = new \Think\Verify();
if($verify->check($code, 1)){
echo "验证码正确";
}else{
$this->success("验证码错误");
}
}
}[
评论( 相关
后面还有条评论,点击查看>>