【问题标题】:Pulling in Magento Session Information is buggy拉入 Magento 会话信息是错误的
【发布时间】:2012-11-05 15:50:11
【问题描述】:

我正在使用此代码结构在自定义页面上提取 Magento 会话信息:

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/");
} 

它在大多数情况下都很好用,但有时它似乎有时无法提取会话信息。我的 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 标签,它会将我带到帐户页面,因为我已登录。

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

【问题讨论】:

  • Mage::getSingleton("core/session", array("name" => "frontend"));删除此行

标签: magento


【解决方案1】:

我不知道您为什么要使用标头,但请尝试使用此代码

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

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

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

【讨论】:

  • 这也不适用于自定义客户资料页面。如果您知道请尽快提供帮助
【解决方案2】:

我遇到了同样的问题,直到我意识到在提取 Magento 会话信息之前我正在为我的自定义页面启动一个新会话。当我扭转这个过程时,它工作得很好。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,然后我将Mage::app("default"); 更改为简单的Mage::app();,它似乎很有效。

    【讨论】:

      【解决方案4】:

      In my case,原来是文件的位置造成了很大的不同。我基本上是在上面尝试了 Kapil 的代码,不同的是我把我的文件放在了 magento 根目录下。

      我想添加我的两条信息;希望这可以回答您的问题。

      编辑: 我使用了类似于 Kapil 的代码。如果您的自定义页面位于单独的子域上,那么您可能需要在 Magento Admin 中正确设置您的 cookie 域(请阅读 cmets:How to access Magento customer's session from outside Magento?)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多