

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{font-family:微软雅黑;margin:0;padding:0;overflow-x:hidden;
overflow-y:hidden;}
div{border:0px solid;}
.menu_top li{list-style:none;float:left;width:20%;font-size:20px;}
.hzhb li{list-style:none;float:left;font-size:15.4px;line-height:25px;}
.left_menu{width:90%;margin:0 auto;}
.left_menu li{list-style:none;}
.input{height:35px;width:70%;}
.submit{width:100px;height:40px;font-size:20px;background:#FFB90F;border:none;border-radius:5px;color:#fff;}
.select_jzc{width:100px;height:35px;}
input{height:30px;width:200px;}
.reset{width:100px;height:40px;font-size:20px;background:#FF83FA;border:none;border-radius:5px;color:#fff;}
</style>
</head>
<body>
<div style="height:100%;width:100%;margin:0 auto;background:#FFFACD;padding-top:10%;">
<div style="width:40%;height:230px;background:#FFBBFF;margin:0 auto;padding-top:20px;box-shadow: 5px 5px 5px #FF82AB;
">
<div style="width:100%;height:50px;">
<div style="width:34%;height:100%;float:left;line-height:50px;text-align:right;">用户名</div>
<div style="width:65%;height:100%;float:left;line-height:50px;">
:<input type="text" name="username" class="username"/>
</div>
</div>
<div style="width:100%;height:50px;">
<div style="width:34%;height:100%;float:left;line-height:50px;text-align:right;">密 码</div>
<div style="width:65%;height:100%;float:left;line-height:50px;">
:<input type="text" name="password" class="pwd"/>
</div>
</div>
<div style="width:100%;height:50px;">
<div style="width:34%;height:100%;float:left;line-height:50px;text-align:right;">验证码</div>
<div style="width:65%;height:100%;float:left;line-height:50px;">
:<input type="text" name="yzm" />
</div>
</div>
<div style="width:100%;height:70px;">
<div style="width:100%;height:100%;line-height:70px;text-align:center;">
  <button class="submit">登 录</button>
  <input type="reset" class="reset" value="重 置" />
</div>
</div>
</div>
</div>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/Js/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function(){
$(".submit").click(function(){
var url2 = "__URL__/login";
var username = $(".username").val();
var pwd = $(".pwd").val();
if(username == ""){
alert("用户名不能为空!");
$(".username").focus();
return false;
}
if(pwd == ""){
alert("密码不能为空!");
$(".pwd").focus();
return false;
}
$.ajax({
url:url2,
data:{'username':username,'password':pwd},
datatype:'json',
type:'post',
success:function(res){
if(res.status == 1){
alert('登录成功!');
window.location.href="__ROOT__/admin.php/Home/Index/show";
}else{
alert("登录失败!");
}
}
})
})
})
</script>
</body>
</html>
public function login(){ $username = $_POST['username'];
$password = $_POST['password'];
//var_dump($_POST);
//exit;
$user = M("Admin"); // 实例化User对象
$result = $user->where('username='.$username. ' AND password='.$password)->find();
//echo $user->getLastSql();
if($result){
$data['status']=1;
$user = session('loginname',$username);
//$this->assign('user',$user);
$this->ajaxReturn($data,'json');
}else{
$data['status']=0;
$this->ajaxReturn($data,'json');
}
}
最佳答案