【发布时间】:2022-08-20 01:06:45
【问题描述】:
这个问题是在过去 2 天尝试了许多解决方案后发布的,但没有任何效果。我的 Codeingiter 4 项目中的会话以一种奇怪的方式表现。我的应用程序中有一个支付模块,PayU 是我的支付网关提供商。支付网关重定向后,PayU 将在我的 URL 中发布一些响应数据。此时会话自动销毁。我不知道为什么,为了您的理解,它正在发生,因为它不是每次都发生,说成功付款后 10 个会话将销毁 7 次。我从控制器内的 PayU 获得所有响应。如果付款因使用而取消,则频率约为 10 次尝试中的 5 次。此问题仅在从 PayU 支付网关重定向后发生,无论支付状态如何。我尝试了this,this,this,this 以及 StackOverflow 以外的许多其他站点。
我在 AlmaLinux 8 中使用 Open LiteSpeed 服务器。我在我的虚拟服务器配置文件中添加了这个
context / {
location $DOC_ROOT/
allowBrowse 1
extraHeaders header edit set-cookie $1;httponly;secure;samesite=none
}
我的 htaccess 文件不包含除用于隐藏的重写规则之外的任何内容上市从网址。
这是我的 .env
app.sessionDriver = \'CodeIgniter\\Session\\Handlers\\DatabaseHandler\' // Initially it was FileHandler
app.sessionCookieName = \'ci_session\'
app.sessionExpiration = 7200
app.sessionSavePath = ci_sessions
# app.sessionMatchIP = false
app.sessionTimeToUpdate = 300
# app.sessionRegenerateDestroy = false
# app.CSPEnabled = false
// Initially all the cookie preferences are commented out experimented with different values.
cookie.prefix = \'\'
cookie.expires = 7200
cookie.path = \'/\'
cookie.domain = \'<domain_name>\'
cookie.secure = true
# cookie.httponly = false
cookie.samesite = \'none\' // I tried Lax also
# 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)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
// Preload any models, libraries, etc, here.
$this->session = \\Config\\Services::session();
session();
}
我在 php.ini 中添加了这一行
session.auto_start = 1
付款后PayU将回复this function 我正在使用 PHP 7.4、Codeigniter 4.1.5 和 Litespeed 1.7.14。
更新
我将 Codeigniter 版本更新为 4.2.3 最新版本,但无法解决此问题。
-
您喜欢使用 cookie 进行自动登录吗?如果你这样做,那么你应该这样做。
-
我对这个问题感到筋疲力尽。我正在使用 codeigniter 3 并检查了 PHP 7.2、8.0 和 8.1 都存在这个问题。我观察到的一个特殊问题是,只有在使用来自 3rd 方域的 POST 数据进行重定向时,会话才会被破坏。否则没问题。
标签: php codeigniter session codeigniter-4