1.login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<script type="text/javascript" src="/Public/Admin/js/jquery.min.1.8.1.js"></script>
<body>
<center style="margin-top: 400px;">
<div id="box">
<div class="login_top">
</div>
<form action="__SELF__" method="post">
手机号 <input type="number" name="mobile" id="mobile" placeholder="输入手机号..."><br><br><br>
密码 <input type="password" name="pass" id="pass" placeholder="输入密码..."><br><br><br>
<div id="captcha-container">
<input type="text" name="yzma" id="yzma" placeholder="验证码">
<img src="{:U('Login/verify_c',array())}" style="height: 43px;" id="shuaxin" title="点击刷新">
</div>
<input type="button" value="登录" id="_submit">
</form>
</div>
</center>
</body>
</html>
2.LoginController.class.php
<?php
namespace Home\Controller;
//加载父控制器类
use Think\Controller;
class LoginController extends Controller{
public function login(){
if(IS_AJAX){
//接收验证码
$verify = I("yzma","");
if(!$this->check_verify($verify)){
//验证码错误
$this->ajaxReturn(1);exit();
}
//接收手机号
$mobile = I("mobile");
//接收密码
$pass = I("pass");
$data = M()->table("user")->where(array("mobile"=>$mobile,"pass"=>md5($pass)))->find();
if(!empty($data)){
//登录成功
$this->ajaxReturn(0);exit();
}else{
//用户名不存在
$this->ajaxReturn(2);exit();
}
}else{
$this->display();
}
}
//取出验证码
function check_verify($code, $id = ""){
$verify = new \Think\Verify();
return $verify->check($code, $id);
}
/*
* 验证码
*/
public function verify_c(){
$Verify = new \Think\Verify();
$Verify->fontSize = 18;
$Verify->length = 4;
$Verify->useNoise = false;
$Verify->codeSet = '0123456789';
$Verify->imageW = 130;
$Verify->imageH = 50;
//$Verify->expire = 600;
ob_clean();
$Verify->entry();
}
}
喜欢点赞+关注老铁
支持原创!