userinfo.myhome.php,ThinkPHP框架中登录验证如何实现?

//登录验证

public function  doLogin(){

$type=I('post.type');

if(!self::check_verify(I('post.code'))){

if($type==home){

$this->error("验证码错误",U("/Home/Index/login"));

}else{

$this->error("验证码错误",U("Login/login"));

}

}

$accountInfo=M('account')->where("account='".I('post.account')."' AND (user_type=3 OR user_type=2)")->find();

if(!$accountInfo){

if($type==home){

$this->error("账号不存在",U("/Home/Index/login"));

}else{

$this->error("账号不存在",U("Login/login"));

}

}

if($accountInfo['password']!=md5(I('post.password')."sqysll")){

if($type==home){

$this->error("密码错误",U("/Home/Index/login"));

}else{

$this->error("密码错误",U("Login/login"));

}

}

$_SESSION['user_type']=$accountInfo['user_type'];//用户类型

$_SESSION['aid']=$accountInfo['id'];

if($type==home){            //0代表官网登录,1代表医院医生后台登录

$_SESSION['type']=0;

}else{

$_SESSION['type']=1;

}

$this->redirect('Index/index');

}

//(TP3.2自带)生成验证码

public function code(){

ob_clean();

$c=I('c');

$config =    array(    'fontSize'    =>    30,    // 验证码字体大小

'length'      =>    3,     // 验证码位数

'useNoise'    =>    false, // 关闭验证码杂点

);

$Verify = new \Think\Verify($config);

$Verify->entry($c);

}

// (TP3.2自带)检测输入的验证码是否正确,$code为用户输入的验证码字符串

function check_verify($code, $id = ''){

$verify = new \Think\Verify();

return $verify->check($code, $id);

}

学到思想就好,希望对你有帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值