0

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.

Fabio
  • 85
  • 1
  • 2
  • 14
  • See if this works for you: http://stackoverflow.com/questions/28954182/get-cart-content-outside-of-magento-but-on-same-domain/28954802#28954802 – Vladimir Ramik Apr 02 '15 at 23:10

1 Answers1

0

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

zhartaunik
  • 932
  • 12
  • 29
  • thks ... you saved my life..... sry but I can't put +1 in your reputation because my reputation is low ... – Fabio Apr 03 '15 at 12:16
  • Hi @zhartaunik: Do you know how we can get the same thing with 'customer/session' ? – 0xh8h Jun 01 '17 at 03:53