2009-07-08 82 views
9

我試圖在我的網站的另一部分訪問Magento客戶會話。如何從Magento外部訪問Magento用戶的會話?

domain.com/shop/ <- Magento 
domain.com/test.php 

商店本身就像一個魅力,但我試着去test.php的內確定如果客戶已登錄,這樣我就可以鏈接到自己的購物車顯示了他的名字。

內容test.php的迄今:

<?php 
require_once dirname(__FILE__).'/shop/app/Mage.php'; 
umask(0); 
Mage::app('default'); 
Mage::getSingleton('core/session', array('name' => 'frontend')); 
var_dump(Mage::getSingleton('customer/session')->isLoggedIn()); 
?> 

我不斷收到布爾(假)返回。我在domain.com/shop/上登錄了Magento,因此預計「真實」。

我忘了什麼嗎?

+0

>「異常:警告:包括(DoppelGangerView.php)......」我的猜測是它不能某種方式找到文件DoppelGangerView.php .. - 它不是位於當前目錄.. - 它不在你的include_path中 – 2010-02-10 17:01:10

回答

14

我會推薦檢查Magento設置的cookie的路徑。最有可能的是,它被設置爲/shop,所以cookie不會被上面的文件訪問。

可以修改Magento用於設置其在控制面板中的cookie下System -> Configuration -> Web (under the General heading) -> Session cookie management

+0

我現在將它設置爲/並且完美地工作!謝謝。 – 2009-07-08 16:05:18

0

confuguration-> web在Magento的版本下的路徑。 1.10.1.1

0

同樣的問題讓我很生氣。我通過以下工作直到最後一個項目解決它:

  • 是否已設置正確的法師存儲ID(當前存儲)?
  • 您是否使用與Magento相同的會話路徑?
  • 您是否使用相同(子)域用於cookie目的?
  • 您是否在Magento內部和外部使用HTTP或HTTPS?

如果您已經檢查了所有上述情況,請確保您在自己的第一次初始化一個核心「前端」會議這樣的:

// Initialise the core "frontend" session 
Mage::getModel('core/session', array('name' => 'frontend')); 

然後你就可以像這樣訪問客戶/會話:

$customer = Mage::getSingleton("customer/session", array('name' => 'frontend'))->getCustomer();