Magento单点登陆-Magento bridge

magento单点登录
magento单点登录

Magento是一款功能强大的开源电子商务软件,与其它各种平台的融合无疑是给Magento锦上添花。

今天我有时间测试下如何脱离Magento控制Magento的用户登入登出。如果你在研究magento单点登陆,希望代码对你有所帮助。代码片段如下。

<?php
//此示例来演示如何控制Magento用户的登入登出。本代码来自 www.hellokeykey.com,转载表明出处
//部分代码来自互联网:http://www.magentocommerce.com/boards/viewthread/11729/P0/
//此例使用Magento 1.5 版本,其它版本可能稍有不同

//这个文件的路径,大家一定不要弄错,不然什么也做不了了
require 'app/Mage.php';

Mage::app();  // or Mage::app('default');  这里的参数什么含义,自己google下

// Here is the magic
// This initializes the session using a cookie named 'frontend' and returns the 'core' namespace (which we ignore)
Mage::getSingleton('core/session', array('name' => 'frontend'));

// // This returns the 'customer' namespace session
$session = Mage::getSingleton('customer/session');

//判断用户是否已经登陆
//出于做测试的目的,已经登陆的,我们做登出处理。没有没有登陆做登陆处理。所以大家要注意*****不要被这个例子弄晕了
if($session->isLoggedIn())
{
   $customer = $session->getCustomer();
   echo '<p>你已经登陆了</p>';
   echo '<p>你的账户ID是 :'.($customer->getId()).'</p>';
   echo '<p>既然你已经登陆我我就测试下让你登出吧</p>';
   $session->logout();
}else
{
//如果用户没有登陆,我们应该验证下用户在其它系统的登陆信息,确定此用户后,将其做登入处理。
echo '你没有登陆,我帮你登陆吧';
//我们可以写一个通过邮箱地址登陆的方法,更有意义
$session->loginById(1);
}

继续阅读“Magento单点登陆-Magento bridge”