ThinkPHP 中验证码的看不清切换
<!--HTML页面-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="__PUBLIC__/js/jquery-1.8.2.min.js"></script>
<form action="{:U('Home/Yzmm/checkLogin')}" method="post">
<div >
<p id="captcha-container">
<input type="code" name="code"/>
<img src="{:U('Home/Yzmm/verify_c','','')}" id="code" style="width:100px; height:30px;" />
<a href="#" onclick="reImg();">看不清,换一张</a>
</p>
<input type="submit" name="submit">
</div>
</form>
<script type="text/javascript">
function reImg(){
var img = document.getElementById("code");
img.src = "{:U('Home/Yzmm/verify_c','','')}?rnd=" + Math.random();
}
</script>
</body>
</html>
<!--PHP 后台数据的处理-->
<?php
namespace Home\Controller;
use Think\Controller;
class YzmmController extends Controller {
public function index(){
$this->display();
}
public function verify_c(){
$Verify = new \Think\Verify();
$Verify->entry();
}
public function del(){
$this->display();
}
function check_verify($code, $id = ''){
$verify = new \Think\Verify();
return $verify->check($code, $id);
}
public function checkLogin(){
$verify = new \Think\Verify();
if($verify->check(I('post.code'))){
$this->success('验证码正确',U('Home/Yzmm/del'),3);
}else{
$this->error('验证码错误',U('Home/Yzmm/index'),3);
}
}
}