Magento 外部登录不会创建会话 cookie [英] Magento external login will not create session cookie

查看:29
本文介绍了Magento 外部登录不会创建会话 cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从外部站点替换 Magento 相当笨拙的 ajax 登录.该网站使用 Magento 作为商店.站点和magento-shop都有自己的登录名,因此当用户登录时,两者同步很重要.这是通过 ajax 调用每个页面重新加载完成的,保持用户登录到 Magento.我想删除它,所以我在每个页面重新加载时创建了一个检查,它将在服务器端执行所有操作.

I am trying to replace a rather clumpsy ajax-login of Magento from an external site. The site uses Magento as a shop. Both the site and the magento-shop has their own logins, therefor when a user logs in it is important that both are synchronized. This was done with an ajax-call each page reload, keeping the user logged into Magento. I want to remove this so I created a check on each page reload which will do everything server-side.

我的问题是,下面的代码不能正常工作:

My problem is, the following code does not work properly:

//Get Magento session-object
Mage::getSingleton("core/session", array("name"=>"frontend"));
$session = Mage::getSingleton("customer/session", array("name"=>"frontend"));

//Check if logged in
if(!$session->isLoggedIn()){                            
    //Not logged in, therefor log in 
    $mpassword = $this->getMagentoPassword();
    $musername = $this->getAddress();   
    try
    {
        $session->login($musername, $mpassword);    
    }catch(Exception $e){
        echo $e->getMessage();
    }                            
}

查看cookie,没有创建任何cookie,ajax-login实际上创建了一个前端"-cookie.我知道上面的代码实际上是登录用户,但没有创建任何会话 cookie.有什么建议?

Looking at cookies, there aren't any created, the ajax-login actually made a "frontend"-cookie. I know the code above actually logs in a user, but there aren't any session cookies created. Any suggestions?

推荐答案

Magento 仅在 $_SESSION 变量未设置时使用您的代码初始化会话,即 session_start()<在实例化核心会话之前未调用/code>.
详情参考Mage_Core_Model_Session_Abstract_Varien::start().

Magento only initializes the session with your code if the $_SESSION variable isn't set, i.e. session_start() wasn't called before the core session is instantiated.
Reference Mage_Core_Model_Session_Abstract_Varien::start() for details.

作为一种解决方案,最简单的方法是在请求期间您网站的其他会话启动之前启动 Magento 会话.
否则,您将不得不复制将会话名称设置为 frontend 并初始化 Magento 会话 cookie 的代码.

As a solution, the easiest way would be to start the Magento session during a request before the other session of your site is started.
Otherwise you will have to duplicate the code that sets the session name to frontend and initializes the Magento session cookie.

这篇关于Magento 外部登录不会创建会话 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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