Magento将Session进行了封装,如果从外部文件中,传递Session数据给Magetno;或者从外部访问Magento中的Session数据,都需要按照Magento的那一套来办。下面的例子是传递Session给Magento:

   require 'app/Mage.php';
   umask(0);

   // Initialize Magento
   Mage::app("default");

   // You have two options here,
   // "frontend" for frontend session or "adminhtml" for admin session
   Mage::getSingleton("core/session", array("name" => "frontend"));

   $_SESSION['Code'] = '258A';

上面的缺点是显而易见的:初始化Magento是项费时费力的工作。但是没办法,常规的Session传值对Magento不起作用。下面是常规方法(注意,不起作用):

   session_start();

   $_SESSION['Code'] = '258A';

Magento将Session划分为下面几个部分。

   Mage::getModel('core/session')

   Mage::getSingleton('adminhtml/session');
   Mage::getSingleton('adminhtml/session_quote');

   Mage::getSingleton('catalog/session');
   Mage::getSingleton('customer/session');
   Mage::getSingleton('checkout/session');

   Mage::getSingleton('api/session');

Magento Session设计太古板了,应该兼容常规的Session使用方式。