2010-07-16 29 views
3

我使用此代碼結構拉動Magento的會話信息的自定義頁面上: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] => 
) 

但是,如果我離開的標題:位置標籤上,它帶給我的帳戶頁面,因爲我在登錄

有其他人遇到此?我如何避免它?我很難過。

+0

Mage :: getSingleton(「core/session」,array(「name」 =>「前端」));刪除此行 – 2012-11-19 09:00:51

回答

1

我不知道,但爲什麼您使用的標題嘗試使用此代碼

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

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

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

這也不適用於自定義客戶資料頁面..如果您知道請儘快幫忙 – 2012-11-19 08:59:09

0

我有同樣的問題,然後我改變Mage::app("default");簡單Mage::app();,它似乎像一個魅力的工作。

1

我有同樣的問題,直到我意識到我拉我的自定義頁面的新會話之前拉Magento會話信息。當我顛倒過程時,它運行良好。

0

In my case,原來,文件的位置做了很多的區別。我基本上試過Kapil的代碼,不同的是我把我的文件放在magento根目錄下。

我想添加我的兩位信息;希望這可能會回答你的問題。編號: 我使用了類似於Kapil的代碼。如果您的自定義頁面位於單獨的子域中,那麼您可能需要在Magento Admin中正確設置您的Cookie域(請閱讀此評論:How to access Magento customer's session from outside Magento?