thinkphp初学者 想让大神用thinkphp做一个简单的登录
展开全部
LoginAction.class.php
<?php
class LoginAction extends Action{
public $user;
protected function _initialize() {
if(session('uid')){
$this->redirect('/member');
}
$this->user = new MemberModel();
}
public function _empty() {
header("HTTP/1.0 404 Not Found");
$this->display('/404');
}
public function index(){
$this->display();
}
//验证码
public function verify(){
import('ORG.Util.Image');
Image::buildImageVerify(4,1,'png','verify');
}
//登录提交
public function login(){
$username = $_POST['username'];
$password = $_POST['password'];
if(!session('?verify')||(session('verify')!= md5($_POST['verify']))) {
$this->error('验证码错误!', '/login');
session('verify',null);
}else{
session('verify',null);
$flag = $this->user->meLogin($username,$password);
if($flag){
$this->success('登录成功', '/member');
}else{
$this->error('用户名或者密码错误,请重新输入', '/login');
}
}
}
MemberModel.class.php
//会员登录
public $passwordSign = "klsdf823uihkjdjkehgfhghhejfjeede";
public $loginLife = 12000; //登录有效时间
function meLogin($username,$password){
$data = M('user')->where('username="'.$username.'"')->find();
if(empty($data)){
return false;
}else{
if($data['password'] == $this->makePassKey($password)){
session('uid', $data['uid']);
session('username', $data['username']);
M('user')->where('uid='.session('uid'))->save(array('lastime'=>time()));
return $data['uid'];
}else{
return false;
}
}
}
//密码加密
function makePassKey($password){
return md5($this->passwordSign.$password);
}
ThinkPHP3.1.2
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询