gpt4 book ai didi

magento - 提取 Magento session 信息有问题

转载 作者:行者123 更新时间:2023-12-02 16:35:50 24 4
gpt4 key购买 nike

我使用以下代码结构在自定义页面上提取 Magento session 信息:

require_once ( "../app/Mage.php" );
umask(0);
Mage::app("default");

Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
$test = array();
//print_r($session);

if($session->isLoggedIn()){
Set some session variables
} //end session check

else {
//They don't belong here. Transfer them to a login page
header("Location: http://www.mydomain.com/customer/account/login/");
}

它在大多数情况下都工作得很好,但有时它似乎无法提取 session 信息。我的 print_r 看起来像这样:

Mage_Customer_Model_Session Object
(
[_customer:protected] =>
[_isCustomerIdChecked:protected] =>
[_skipSessionIdFlag:protected] =>
[_data:protected] => Array
(
[_session_validator_data] => Array
(
[remote_addr] => an.ip.addr.ess
[http_via] =>
[http_x_forwarded_for] =>
[http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)
)

[session_hosts] => Array
(
[www.mydomain.com] => 1
)

)

[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
)

但是,如果我保留 header:location 标记,它会将我带到帐户页面,因为我已登录。

还有其他人经历过这种情况吗?我该如何避免呢?我被难住了。

最佳答案

我不知道你为什么使用 header ,但尝试使用此代码

require_once ( "../app/Mage.php" );
umask(0);
Mage::app("default");

$session = Mage::getSingleton("customer/session");

if($session->isLoggedIn()){
var_dump($session->getData());
}

关于magento - 提取 Magento session 信息有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3262289/

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