Magento 会话无法在外部页面(同一域)中工作
外部页面(同一域)中的 Magento 会话运行不佳,我已经检查了此处的所有其他主题,但它正在运行的任何解决方案。
require_once ( "../app/Mage.php" );
umask(0);
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
if($session->isLoggedIn()){
//do it
} else {
// Transfer them to a login page
header("Location: http://www.mydomain.com/customer/account/login/");
}
我无法让它工作,我已经检查了所有地方的建议,但没有任何作用。
Magento Session in external page (same domain) is not working well, I've checked all the other topics here but any solution it is working.
require_once ( "../app/Mage.php" );
umask(0);
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
if($session->isLoggedIn()){
//do it
} else {
// Transfer them to a login page
header("Location: http://www.mydomain.com/customer/account/login/");
}
I can not get this to work, I have checked all recommendations everywhere and nothing work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的问题是你已经启动了一个会话,所以你尝试启动 magento 会话并从中获取数据失败。
如果您查看 Mage_Core_Model_Session_Abstract_Varien 内部,它所做的第一件事就是查看 $_SESSION 变量是否已设置,如果已设置则返回。您可以在那里设置调试器断点并验证是否不确定。
您可以关闭另一个会话并启动 magento 会话来获取数据,或者您可以让两者共享同一个会话
I think your issue is that you already have a session started, so your attempts to start a magento session and get data from it are failing.
If you look inside Mage_Core_Model_Session_Abstract_Varien, the first thing it does is look to see if the $_SESSION variable is already set and return if it is. You could set your debugger breakpoint there and verify if you aren't sure.
You could close the other session and start the magento session to get your data, or you could get both to share the same session
仅供参考,在 header() 函数之后,应该有另一行:
以使重定向起作用。
(显然这更多地属于评论而不是答案,但我还没有权利在任何地方发表评论。)
Just for your information, after the header() function, there should be another line:
for the redirection to work.
(Apparently this belongs more to a comment rather than an answer, but I don't have the privilege to comment everwhere yet.)
你可以尝试这些行,它们看起来很相似,但在 Magento 1.5.1 上对我有用。
You can try these lines instead, they looks similar, but work for me on Magento 1.5.1..