tp5验证码的使用

<div><img id="verify_img" src="{:captcha_src()}" alt="验证码" onclick="refreshVerify()"></div>

<a href="javascript:refreshVerify()"><span id="sx" style="cursor:pointer;font-size:14px;color:#eee;">看不清楚,<br>换一张</span></a>

 

<script type="text/javascript">
function refreshVerify() {
var ts = Date.parse(new Date())/1000;
var img = document.getElementById('verify_img');
img.src = "/captcha?id="+ts;
}

</script>

public function login()
{
if(empty(input('param.'))){
return $this->fetch();
}else{
$verifyCode = input('post.verifyCode');
if(captcha_check($verifyCode)){
$uid = input('post.uid');
$pwd = input('post.pwd');
if($uid!="" && $pwd!=""){
$admin = db("Admin");
$admin_forbid = $admin->where("admin_account='$uid'")->value('admin_forbid');
$admin_password = $admin->where("admin_account='$uid'")->value('admin_password');
if($admin_forbid=='是'){
echo "<script>alert('该用户已被禁用,请联系管理员')</script>";
return $this->fetch();
}elseif($pwd==$admin_password){
session('admin_account', $uid); // 跳转页面之前将$uid存入session
$ip=$_SERVER["REMOTE_ADDR"];
$admin->execute("update admin set admin_loginnum=admin_loginnum+1,admin_loginip='$ip',admin_logintime=now() where admin_account='$uid'");
$this->redirect('index/index');
}else{
echo "<script>alert('登录失败')</script>";
return $this->fetch();
}
}else{
echo "<script>alert('用户名或者密码不能为空!')</script>";
return $this->fetch();
}
}else{
echo "<script>alert('验证码不正确!')</script>";
return $this->fetch();
}
}
}

posted @ 2018-01-30 19:51  后海大鲨鱼、  阅读(1109)  评论(0编辑  收藏  举报