Get magento session variable in another page

14,174

If we create a session in Magento, then we can only use that session in Magento files like in the magento/app folder. If you want to use that session in external files create by you then you must first get the session in another Magento default file and then call a jquery ajax function and pass session variable through it to get it in an external file. You also pass the variable through ajax without the use of the session.

Set session data like this.

$fldata = 'work for set data';
Mage::getSingleton('core/session')->setMyCustomData($fldata);

and get data like this.

session_start();
$sessionfree = Mage::getSingleton('core/session', array('name' => 'frontend'));
$abcfree = $sessionfree->getMyCustomData();
Share:
14,174
Admin
Author by

Admin

Updated on June 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I set array variable in session in magento modal page and want to retrieve in another page like getuserdata.php but not get in another page. I set variable and get in one page then in completely retrieve.

    My code is like..

    //first page code.

    $session = Mage::getSingleton("core/session",  array("name"=>"frontend"));
    $fldata = 'work for set data';
    $session->setData("free_auth", $fldata);
    

    //another page code.

    session_start();
    require_once ("../../app/Mage.php");
    umask(0);
    Mage::app('default');
    $session = Mage::getSingleton("core/session",  array("name"=>"frontend"));
    $stl1 = $session->getData("free_auth");
    

    Anyone can help me for that stuff problem..