Magento 检查客户是否从洋红色外部登录


Magento Check if customer is logged in from outside of magento

我正在尝试实现"登录/注销"链接,就像在顶部菜单中一样,但在洋红色之外的页面上。这是我到目前为止尝试过的:我没有使用普通的"登录"链接,而是使用此脚本加载Mage,然后根据是否登录的客户显示链接。

<?php
    require_once('tmg/app/Mage.php'); //Path to Magento
    umask(0);
    Mage::app();
?>
<?php if (Mage::getSingleton('customer/session')->isLoggedIn()==0): ?>
<a href="<?php echo $this->getUrl('customer/account/login') ?>"><?php echo $this- >__('Log In') ?></a>
<?php else: ?>
    <a href="<?php echo $this->getUrl('customer/account/logout') ?>"><?php echo $this->__('Log Out') ?></a>
<?php endif ?>

浏览器中显示的是此代码之前的页面,之后绝对没有内容。我还尝试将其单独放入测试文件中并运行它,但它也会导致一个空的浏览器窗口,没有源代码或任何可见的东西。我做错了什么?

试试这个。

require_once('tmg/app/Mage.php');
    umask(0);
    Mage::app();
//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$customer_data = Mage::getModel('customer/customer')->$session->id;
//CHECK IF LOGGED IN
if($session->isLoggedIn()){
?>
<a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>customer/account/logout"><?php echo "Log Out"; ?></a>
<?php 
} else {
?>
<a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>customer/account/login"><?php echo "Log in"; ?></a>
<?php 
exit;
}

请检查这是否有帮助!

require_once 'app/Mage.php';

umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$sessionCustomer = Mage::getSingleton("customer/session");
if($sessionCustomer->isLoggedIn()) {
  echo "Logged";
} else {
   echo "Not Logged";
}

有关更多详细信息,请查看此处 Magento 客户登录

上述解决方案在Firefox中对我有用,但在Chrome中不起作用。我不得不添加

Mage::getSingleton('customer/session')->start();

行后

Mage::app('default');

然后它似乎工作正常。(马真托 1.9)