Magento 1.9 – How to Check if a Session Variable Exists

magento-1.9session

How we can check if a session variable exists in Mangento. I know how to create a new variable.

Mage::getSingleton('core/session')->setMyValue($myValue);

My aim is to check if session variable MyValue exists. If exists do nothing otherwise create one

Best Answer

You can do:

if (Mage::getSingleton('core/session')->getMyValue())
{
    // Value exists, do stuff
}
else
{
    // Value does not exists, do other stuff
}
Related Topic