The Magento System is in "web/shop". How do I set a session variable outside of it (e.g. in "web/index.php")? And how do I read it inside of Magento (e.g. in "web/shop/app/...")?

The scenario is the following: A user visits a landing page (e.g. "web/lp/example.php"). Dependent on the landing page, certain contents in "web/shop" must be customized only for that session. So a session variable must be set in "web/lp/example.php" to be read later in the shop.

Thanks for your help!

1 Answer 1


Try to insert in your index file (outside of Magento):

require_once 'path/to/your/app/Mage.php';
Mage::getSingleton('core/session', ['name' => 'frontend']);

It will give you an access to Magento core functionality like sessions etc. After that you will be able to set your custom variable

Mage::getSingleton('core/session')->setMyVariable('Some value');

Then simply call anywhere in Magento:

  • I'm not sure if setting the variable works (because there's no error message). But when I want to get it in Magento, it returns NULL. Do I need any of your first three code lines when getting the variable?
    – elterr1ble
    Nov 2, 2016 at 10:48
  • I need help please.. Does nobody know the answer to my problem?
    – elterr1ble
    Nov 4, 2016 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.