Session Variable outside magento

吃可爱长大的小学妹 提交于 2020-01-06 09:38:12

问题


I have to read a $_SESSION['name'] in a file outside magento or better is in /magento/folder. I tried any solution without good result.

Example

Mage::getSingleton('core/session')->setUName($_SESSION['username']);

In external file use this code:

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

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Mage::init();

$_SESSION['username'] = Mage::getSingleton('core/session')->getUName();

Result??? Variable empty....

I'm crazying with magento.... I need this one variable!!!!

If someone can help me I'll say thanks.


回答1:


Quick solution:

Mage::getSingleton('core/session', array('name' => 'frontend'))->getUName();

Explanation:

Session start here: Mage_Core_Model_Session_Abstract_Varien::start()

When default magento is trying to start session it runs with param: $sessionName = 'frontend'. When you run Mage::getSingleton('core/session') - you instantiate session without any params. And you didn't pull necessary session. So that because you need to add one more param with session name



来源:https://stackoverflow.com/questions/29422106/session-variable-outside-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!