

为何我退出登录后还显示请不要重复登录?session没清空?不科学啊
Base.php控制器:
namespace app\admin\common;
use think\Controller;
use think\Session;
class Base extends Controller{
// Base.php控制器主要完成三项工作:
// 1.创建登录标志常量,
// 2.对未登录进行处理,
// 3.对已登录进行处理,
protected function _initialize(){
parent::_initialize();
// 在公共控制器的初始化方法中,创建一个常量来判断用户是否登录或已登录
define('USER_ID',Session::get('user_id'));
}
// 判断用户是否登录,在后台入口调用
protected function isLogin(){
// 如果登录常量为空,表示没有登录
if(is_null('USER_ID')){
$this->error('未登录,无权访问...','login/index');
}
}
// 如果用户已经登录,将不再登录
protected function alreadyLogin(){
//如果登录常量为空,表示没有登录
if(!is_null('USER_ID')){
$this->error('请不要重复登录...','index/index');
}
}
}
?>
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
if(is_null('USER_ID')){
}
if(!is_null('USER_ID')){
}
两个'USER_ID'单引号去掉
is_null 是判断变量是不是 null 类型的
你换成 empty() 就行