问题
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