如何从 Magento 外部访问 Magento 用户的会话? [英] How to access Magento user's session from outside Magento?
问题描述
我正在尝试访问我网站另一部分的 Magento 客户会话.
Im trying to access the Magento customer session in another part of my website.
domain.com/shop/ <- Magento
domain.com/test.php
商店本身就像一个魅力,但是我试图在 test.php 中确定客户是否登录,所以我可以显示他的名字和他的购物车的链接.
The shop itself works like a charm, however im trying to determine within test.php if a customer is logged in, so I can display his name with a link to his cart.
到目前为止 test.php 的内容:
Contents of test.php so far:
<?php
require_once dirname(__FILE__).'/shop/app/Mage.php';
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
var_dump(Mage::getSingleton('customer/session')->isLoggedIn());
?>
我不断收到 bool(false) 返回.我已通过 domain.com/shop/登录 Magento,因此应该是true".
I keep getting bool(false) returned. I'm logged into Magento at domain.com/shop/ so ‘true’ is expected.
我是不是忘记了什么?
推荐答案
我建议检查 Magento 设置的 cookie 的路径.最有可能的是,它被设置为 /shop
,因此 cookie 将无法被它上面的文件访问.
I would recommend checking the path of the cookie that Magento sets. Most likely, it is set to /shop
, so the cookie will not be accessible to your file above it.
您可以在System->下的控制面板中修改Magento用来设置其cookie的路径.配置 ->Web(在一般标题下)->会话cookie管理
这篇关于如何从 Magento 外部访问 Magento 用户的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!