PHP会话行为奇怪
当我在本地计算机上运行以下代码(使用MAMP PRO的MACOS)时,它可以正常运行。但是,当我将其部署到运行CentOS的实时服务器时,它不想将Session Cookie存储在我的浏览器中。
$cookieParams = session_get_cookie_params();
$lifetime = (!empty($session_lifetime = env('SESSION_LIFETIME'))) ? $session_lifetime * 60 : 3600;
session_set_cookie_params([
'lifetime' => $lifetime,
'path' => $cookieParams['path'],
'domain' => env('APP_URL'),
'secure' => true,
'httponly' => true,
'samesite' => 'lax' // lax
]);
session_name('WEBSESSION-UUID');
session_save_path(Path::storage_path('framework/sessions'));
ini_set('session.gc_probability', 1);
ini_set('session.gc_maxlifetime', $lifetime);
if (empty($_SESSION['SESSION_ID'])) {
if (self::isSessionStarted() === false) session_start();
$_SESSION['SESSION_ID'] = hash('crc32b', uniqid() . date('Y-m-d H:i:s') . uniqid());
}
session_regenerate_id(true);
会话是在正确的位置中创建的,该位置在session_save_path中说明。但是,每次我重新加载页面时,它都会加载一个新页面。该域也是我用来调用页面的确切域。
Session_Save_Path文件夹的权限设置为755,Apache:Apache作为所有者。
会议再次成功创建。如果我在session_start之后打印session_id,它将输出一个会话。它似乎确实在Cookie中的某个地方,该Cookie必须将PHP会话链接到用户会话。
我不是注意到什么真的很明显吗?
编辑:永远不会发生任何错误。我唯一获得的错误是权限错误,我通过chown -r apache:apache文件夹/
修复了错误。
When I run the following code on my local machine (macOS using MAMP Pro), it works fine. Yet when I deploy the same to a live server running centOS, it doesn't want to store the session cookie in my browser.
$cookieParams = session_get_cookie_params();
$lifetime = (!empty($session_lifetime = env('SESSION_LIFETIME'))) ? $session_lifetime * 60 : 3600;
session_set_cookie_params([
'lifetime' => $lifetime,
'path' => $cookieParams['path'],
'domain' => env('APP_URL'),
'secure' => true,
'httponly' => true,
'samesite' => 'lax' // lax
]);
session_name('WEBSESSION-UUID');
session_save_path(Path::storage_path('framework/sessions'));
ini_set('session.gc_probability', 1);
ini_set('session.gc_maxlifetime', $lifetime);
if (empty($_SESSION['SESSION_ID'])) {
if (self::isSessionStarted() === false) session_start();
$_SESSION['SESSION_ID'] = hash('crc32b', uniqid() . date('Y-m-d H:i:s') . uniqid());
}
session_regenerate_id(true);
Sessions are created in the correct location, which is stated in the session_save_path. Yet every time I reload the page, it'll load a new one. The domain is also the exact domain I am using to call the page.
Permissions of the session_save_path folder are set to 755 with apache:apache as the owner.
Sessions are again, successfully created. If I print the session_id after session_start, it'll output a session. It really appears to be somewhere in the cookie, which has to link the php session to the user session.
Am I not noticing something really obvious?
Edit: No errors what so ever. The only error I got was a permission error, which I fixed by chown -R apache:apache folder/
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论