gpt4 book ai didi

php - Magento 2 session 数据在谷歌浏览器中被删除

转载 作者:行者123 更新时间:2023-12-03 15:48:07 25 4
gpt4 key购买 nike

问题:
当我的 magento2.3 应用程序将用户重定向到支付网关时,我可以访问所有 session 数据。但是当它从那里返回时,它没有结帐 session 数据或任何 session 数据。这只发生在谷歌浏览器上
我已经探索过的东西
从 google chrome 发行说明 (https://www.chromium.org/updates/same-site) 我可以看到他们已将 samesite 默认值更改为“Lax”,并禁用此功能。
寻找解决方案
我想为我对任何第三方服务的所有传出请求赋予 samesite=None 值。任何帮助或领导将不胜感激。

最佳答案

您可以尝试通过以下步骤设置 samesite=None..
文件:etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Element\Js\Cookie">
<plugin name="afterGetPath" type="namespace\module\Plugin\View\Element\Js\ManagePath" sortOrder="10"/>
</type>
</config>
文件:插件/ View /元素/Js/ManagePath.php
namespace namespace\module\Plugin\View\Element\Js;

use Magento\Framework\View\Element\Js\Cookie;

class ManagePath
{
public function afterGetPath(\Magento\Framework\View\Element\Js\Cookie $subject, $path)
{

if (preg_match('/SameSite/', $path)) {
$path_array = explode(';', $path);
$path = $path_array[0];
}

return $path;
}
}
文件:etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<preference for="Magento\Framework\Session\Config\ConfigInterface" type="namespace\module\Session\CustomConfig"/>
</config>

文件: session /CustomConfig.php

namespace namespace\module\Session;

use Magento\Framework\Session\Config as DefaultConfig;

class CustomConfig extends DefaultConfig
{
public function setCookiePath($path, $default = null)
{
parent::setCookiePath($path, $default);

$path = $this->getCookiePath();

//check and update path of cookie
if (!preg_match('/SameSite/', $path)) {
$path .= '; SameSite=None';
$this->setOption('session.cookie_path', $path);
}

return $this;
}
}

注意 : 用你的 替换命名空间和模块命名空间 模块 .

关于php - Magento 2 session 数据在谷歌浏览器中被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63635865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com