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

CodeIgniter 4中PayU支付网关重定向后Session随机销毁问题求助

问题:CodeIgniter 4集成PayU支付后Session随机销毁

我已尝试多种解决方案达两天之久,但均未奏效。我的CodeIgniter 4项目中Session表现异常:应用内集成PayU支付网关模块后,支付网关重定向并向我的URL提交响应数据时,Session会自动销毁。该问题并非每次都会出现:成功支付后,10次中有7次会出现Session销毁;用户取消支付时,10次中有5次会出现。无论支付状态如何,仅在PayU支付网关重定向后才会触发此问题。我已尝试过StackOverflow等多个站点的方案,均无效。


环境信息

  • 服务器:AlmaLinux 8 + Open LiteSpeed 1.7.14
  • PHP版本:7.4
  • CodeIgniter版本:已从4.1.5升级至4.2.3,问题仍存在

Open LiteSpeed虚拟服务器配置

context / {
    location    $DOC_ROOT/
    allowBrowse    1
    extraHeaders  header edit set-cookie $1;httponly;secure;samesite=none
  }

.htaccess配置

仅包含用于隐藏URL中public目录的重写规则

.env配置

app.sessionDriver = 'CodeIgniter\Session\Handlers\DatabaseHandler' // 最初使用的是FileHandler
app.sessionCookieName = 'ci_session'
app.sessionExpiration = 7200
app.sessionSavePath = ci_sessions
# app.sessionMatchIP = false
app.sessionTimeToUpdate = 300
# app.sessionRegenerateDestroy = false

# app.CSPEnabled = false
// 最初所有cookie配置均为注释状态,已尝试过不同取值
cookie.prefix = ''
cookie.expires = 7200
cookie.path = '/'
cookie.domain = '<domain_name>'
cookie.secure = true
# cookie.httponly = false
cookie.samesite = 'none' // 也试过Lax
# cookie.raw = false

security.csrfProtection = 'cookie'
security.tokenName = 'csrf_token_name'
security.headerName = 'X-CSRF-TOKEN'
security.cookieName = 'csrf_cookie_name'
security.expires = 7200
security.regenerate = true
security.redirect = true
security.samesite = 'Lax'
curlrequest.shareOptions = true

BaseController代码修改

public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
    // 请勿修改此行
    parent::initController($request, $response, $logger);

    // 预加载模型、库等

    $this->session = \Config\Services::session();
    session();
}

php.ini修改

session.auto_start = 1

更新说明

已将CodeIgniter版本更新至最新的4.2.3,但问题仍未解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 14:36:20