magento之外的会话变量 [英] Session Variable outside magento

查看:85
本文介绍了magento之外的会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在magento以外的文件中读取$_SESSION['name'],或者更好的是在/magento/folder中. 我尝试了任何解决方案均未取得良好结果.

I have to read a $_SESSION['name'] in a file outside magento or better is in /magento/folder. I tried any solution without good result.

示例

Mage::getSingleton('core/session')->setUName($_SESSION['username']);

在外部文件中,使用以下代码:

In external file use this code:

require_once("../app/Mage.php");
umask(0);
Mage::app();

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Mage::init();

$_SESSION['username'] = Mage::getSingleton('core/session')->getUName();

结果???变量为空....

Result??? Variable empty....

我在为magento疯狂....我需要这个变量!!!

I'm crazying with magento.... I need this one variable!!!!

如果有人可以帮助我,我会说谢谢.

If someone can help me I'll say thanks.

推荐答案

快速解决方案:

Mage::getSingleton('core/session', array('name' => 'frontend'))->getUName();

说明:

会话从此处开始:Mage_Core_Model_Session_Abstract_Varien :: start()

Session start here: Mage_Core_Model_Session_Abstract_Varien::start()

默认的magento尝试启动会话时,它会使用以下参数运行: $ sessionName ='frontend'.当您运行 Mage :: getSingleton('core/session')时,您将实例化会话而没有任何参数.而且您没有进行必要的会话.这样,因为您需要再添加一个带有会话名称的参数

When default magento is trying to start session it runs with param: $sessionName = 'frontend'. When you run Mage::getSingleton('core/session') - you instantiate session without any params. And you didn't pull necessary session. So that because you need to add one more param with session name

这篇关于magento之外的会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆