Magento external login will not create session cookie

谁说胖子不能爱 提交于 2019-12-02 22:29:23

问题


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();
    }                            
}

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/9206397/magento-external-login-will-not-create-session-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!