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

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

问题描述

我正在尝试从外部站点替换一个相当笨拙的Magento的ajax登录.该站点将Magento用作商店.站点和magento商店都有自己的登录名,因此,当用户登录时,同步是很重要的.每次重新加载页面时,通过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登录实际上创建了一个前端" -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())的情况下,使用您的代码初始化会话. .
有关详细信息,请参考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天全站免登陆