在另一个页面中获取 magento 会话变量

2021-12-19 00:00:00 session php magento

我在 magento 模态页面的会话中设置了数组变量,想在另一个页面(如 getuserdata.php)中检索但不进入另一个页面.我设置变量并进入一页然后完全检索.

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.

我的代码就像..

//第一页代码.

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

//另一个页面代码.

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

推荐答案

如果我们在 Magento 中创建会话,那么我们只能在 Magento 文件中使用该会话,例如在 magento/app 文件夹中.如果您想在您创建的外部文件中使用该会话,那么您必须首先在另一个 Magento 默认文件中获取该会话,然后调用 jquery ajax 函数并通过它传递会话变量以将其获取到外部文件中.您还可以在不使用会话的情况下通过 ajax 传递变量.

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.

像这样设置会话数据.

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

并像这样获取数据.

session_start();
$sessionfree = Mage::getSingleton('core/session', array('name' => 'frontend'));
$abcfree = $sessionfree->getMyCustomData();

相关文章