zoukankan      html  css  js  c++  java
  • thinkphp5 tp5 会话控制 session 登录 退出 检查检验登录 判断是否应该跳转到上次url

    <?php
    namespace appadmincontroller;
    use thinkDb;
    use thinkValidate;
    use thinkController;
    use thinkfacadeSession;
    use appadminmodelOrderModel;
     
    class Order extends Controller
    {
        public function initialize()
        {
            $event = controller('login','controller');
            $event->check();
        }   
     
        //用户登录
        public function index()
        {
            if($this->request->isAjax()){
                $account = $this->request->param('account');
                $password = $this->request->param('password');
                $admin = Db::table('admin')->where(['account'=>$account, 'password'=>$password])->find();
                if($admin['id']){
                    Session::set('admin',$admin);
     
                    //判断是否应该跳转到上次url
                    if(!empty(Session::get('redirect_url'))){
                        $url = Session::get('redirect_url');
                        Session::delete('redirect_url');
                    }else{
                        $url = url('index/index');
                    }
     
                    exit( json_encode(['check'=>1, 'msg'=>'登录成功!', 'url'=>$url]) );
                     
                }else{
                    exit( json_encode(['check'=>0, 'msg'=>'账号或密码错误']) );
                }
            }
     
            if(is_numeric(Session::get('admin.id'))){
                $this->redirect('index/index');
            }
            return $this->fetch();
        }
     
        public function check()//检查登录
        {
            if(!is_numeric(Session::get('admin.id'))){
                 
                if($this->request->isAjax()){
                    exit( json_encode(['check'=>2, 'url'=>url('login/index')]) );
                }else{
                    redirect()->remember();
                    $this->redirect('login/index');               
                }
            }
        }
     
        public function out() {
            Session::clear();
            $this->redirect('index/index');
        }
     
    }
  • 相关阅读:
    原码、反码、补码详解
    进制转换
    目录
    Window【目录】
    排序算法——冒泡排序
    算法的时间复杂度与空间复杂度
    排序算法
    递归—八皇后问题
    递归—迷宫问题
    递归
  • 原文地址:https://www.cnblogs.com/shaoing/p/8920697.html
Copyright © 2011-2022 走看看