💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
建一个Base控制器,所有需要登录才能访问的页面都继承这个控制器 ``` 方法一:前置方法 //前置方法:运行时先执行这个方法 protected $beforeActionList = ["isLogin"]; protected function isLogin(){ if (!session(('adminname'))){ return $this->redirect('admin/login/login'); } } ``` ``` 方法二:构造函数 public function __construct(App $app = null) { parent::__construct($app); if (!Cookie::get("username")){ return $this->error("请进行登录",url("admin/login/index")); } } ``` ``` 方法三:中间件拦截 在app\admin下建http\middleware\Check类 namespace app\admin\http\middleware; use think\Controller; use think\facade\Session; class Check extends Controller { public function handle($request, \Closure $next) { if ($this->request->controller() !=='Login'){ if (!Session::get("userId")){ $this->error("请先登录",url("admin/login/index")); } } return $next($request); } } 然后在middleware.php文件中返回这个类 app\admin\http\middleware\Check::class, ```