5

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..

2
  • 1
    Already tried to remove the session_start from the second snippet? Magento uses Zend_Session. An explicit session_start can cause issues. Commented Sep 25, 2012 at 8:24
  • Other than that, tried to namespace your session variable name, e.g. myspace_free_auth, to avoid variable name collisions? Commented Sep 25, 2012 at 8:28

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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