密码错误三次限制登录
HTML页面的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<center>
<table>
<tr>
<td>用户名</td>
<td><input type="text" class="name"></td>
<td><span class="sp1"></span></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" class="pwd"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="登录" class="sub"></td>
</tr>
</table>
</center>
<script src="__STATIC__/jquery.min.js"></script>
<script>
//判断用户
$(".name").blur(function () {
var name=$(".name").val();
//请求
$.post(
"{:url('index/user_pan')}",
{
name:name
},
function (data) {
if(data==1)
{
$(".sp1").empty();
$(".sp1").append("该用户不存在")
}else{
$(".sp1").empty();
$(".sp1").append("√")
}
}
)
})
$(".sub").click(function () {
var name=$(".name").val();
var pwd=$(".pwd").val();
//请求
$.post(
"{:url('index/login_do')}",
{
name:name,
pwd:pwd
},
function (data) {
if(data==1)
{
alert("密码错误");
}else if(data==2)
{
alert("45秒后登录")
}else if(data==3)
{
alert("着啥急,还没到45秒后呢!")
}else if(data==4)
{
alert("登录成功")
}
}
)
})
</script>
</body>
</html>
PHP页面的代码:
//登录
public function login()
{
return view("login");
}
//判断用户
public function user_pan()
{
$name=Request::instance()->param("name");
$a=Db::table("user")->where("name='$name'")->find();
Session::set("b_id",$a['b_id']);
if(!$a){ return 1; }//判断用户
}
//登录的值
public function login_do()
{
$b_id=Session::get("b_id");
$stat=Db::table("user")->where("b_id=$b_id")->find();
$static=$stat['static'];
if($static==1)
{
Session::set("add_time",time(),'think');
$now_time=$stat['now_date'];
$add_time=Session::get("add_time",'think');
$time_aa=$add_time-$now_time;
if($time_aa<=45)
{
return 3;
}else{
Db::table("user")->where("b_id='$b_id'")->update(['sum'=>0,'sta tic'=>0]);
}
}
$zong_shu=Db::table("user")->where("b_id='$b_id'")->find();
$shu=$zong_shu['sum'];
if($shu>=2)
{
Db::table("user")->where("b_id='$b_id'")->update(['static'=>1]);
return 2;//计算总数大于三则不能登录
}
else
{
$name=Request::instance()->param("name");
$pwd=Request::instance()->param("pwd");
$a=Db::table("user")->where("name='$name'and pwd='$pwd'")->find();
if(!$a)
{
$b_id=Session::get("b_id");
$b=Db::table("user")->where("b_id='$b_id'")->find();
$sum=$b['sum']+1;
$now_date=time();
Db::table("user")->where("b_id='$b_id'")->update(['sum'=>"$sum",'now_date'=>$now_date]);
return 1;
}else{
return 4;//登录成功
}
}
}
你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。