You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CI4 + Ion-Auth 登录后刷新/提交表单自动登出问题求助

求助:CodeIgniter 4 + Ion-Auth登录后刷新/提交表单自动登出问题

我开发的一个需要登录访问的页面,首次登录成功后能正常跳转首页,控制台也能看到会话变量,但刷新页面或提交该页面表单时,会被重定向到登录页并自动登出。

异常现象

  • 使用生产数据库而非开发数据库时,代码运行正常,能保持登录状态(初步怀疑数据库问题);
  • 同事的开发环境(代码版本一致)使用我开发库的登录账号,无任何问题(又怀疑浏览器问题);
  • 更换浏览器、换设备、清除Cookie后,问题仍存在。

使用技术栈及核心代码

我们使用Codeigniter 4框架,搭配CodeIgniter-Ion-Auth进行身份验证,以下是控制器中检查登录状态的代码:

$this->ionAuth = new \IonAuth\Libraries\IonAuth();
//a user must be logged in to go here so check if they are logged in and are an admin
if (!$this->ionAuth->loggedIn()) {    
            $this->session->setTempdata('message', 'Please log in to access this part of the website');
            // for CI4/CI3 redirection use just uri_string
            $this->session->setTempdata('destination', uri_string(current_url()));
            // for CI4 use url
            $this->session->setTempdata('url', current_url());
            return redirect()->to('auth/login');
            exit;
        }

已尝试的排查操作

  • 在开发数据库中创建新用户登录;
  • 在我的开发环境中使用同事的开发库登录凭证;
  • 清除Cookie、使用隐身模式、更换设备;
  • 刷新DNS、重启路由器和电脑。

恳请各位提供解决思路!

内容的提问来源于stack exchange,提问作者xanabobana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 16:10:13