后台增加判断登录中间件

think目录下新增Bash.php文件

<?php
namespace think;

class Base extends Controller
{
    protected function _initialize()
    {
        if(empty(session('name', '', 'admin'))){
            header('location:/admin/login.html');
            exit;
        }
    }

    
}

admin代表作用域。

加了之后,后台除了登录界面控制器引用原始的Controller,其余控制器全部集成Base。

附上thinkphp5,session手册

https://www.kancloud.cn/manual/thinkphp5/126166

原文地址:https://www.cnblogs.com/chenliuxiao/p/12579909.html