LANG ] E:\phpStudy\PHPTutorial\WWW\hycy\thinkphp\lang\zh-cn.php
[ ROUTE ] array ( )
[ HEADER ] array ( 'cookie' => 'thinkphp_show_page_trace=1|2', 'accept-language' => 'zh-CN,zh;q=0.8', 'accept-encoding' => 'gzip, deflate', 'referer' => 'http://a.com/index.php/index/user/login', 'accept' => 'text/html,application/xhtml xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'content-type' => 'application/x-www-form-urlencoded', 'user-agent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.3.2.17331', 'upgrade-insecure-requests' => '1', 'origin' => 'http://a.com', 'cache-control' => 'max-age=0', 'content-length' => '23', 'connection' => 'close', 'host' => 'a.com', )
[ PARAM ] array ( 'name' => 'jh', 'password' => '123456', )
[ VIEW ] E:\phpStudy\PHPTutorial\WWW\hycy\application\index\view\user\login.html [ array ( 0 => 'title', ) ]
if(Request::isAjax()){
//数据验证
$data = Request::post();//获取ajax提交数据
$rule = ['name|姓名'=> 'require|length:2,20|chsAlphaNum',
'password|密码'=>'require|alphaNum',];
$res=$this->validate($data,$rule);
if (true !== $res){ //验证失败
return ['status'=> -1, 'message'=>$res];
}else { //验证成功
//2. 查询数据表zh_user中,并对结果进行判断
$result = Syuser::get(function($query) use ($data){
$query->where('name',$data['name'])
->where('password',sha1($data['password']));
});
// halt($result); //测试查询结果
if(null == $result){
return ['status'=>0, 'message'=>'邮箱或密码不正确,请检查~~'];
} else{
//将用户ID写入session中
Session::set('user_id', $result->id);
Session::set('user_name', $result->name);
Session::set('is_admin', $result->is_admin);
return ['status'=>1, 'message'=>'恭喜,登录成功~~'];
}
}
}else{
$this->error('请求类型错误','login');
}
If there is no response when clicking login, there should be a problem with the front-end AJAX writing. Open the browser console and check for JS errors.