I am trying to set the cookie on user login basis and want to empty on logout. Login working perfect but logout didn't work. For that purpose I used this XML code :


And PHP code is in observer :


class Easylife_Sales_Model_Observer 

    public function setHandle(Varien_Event_Observer $observer)
  Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));

     $customerData = Mage::getSingleton('customer/session')->getCustomer();
   $name = 'loginuser';
          $value = $customerData->getId();

          Mage::getModel('core/cookie')->set($name, $value);

 }else if(Mage::getModel('core/cookie')->get('loginuser') > 0 ){



     public function customerLogout(Varien_Event_Observer $observer)

      if (isset($_COOKIE['loginuser'])) {
        setcookie('loginuser', null, -1, '/');
       $cookieName = 'loginuser';
     $session = Mage::getSingleton("core/session", array("name"=>"frontend"));

       //echo Mage::getModel('core/cookie')->get('loginuser');exit();



I am trying to delete the cookie value and user session on logout click. It shows message of logout successfully and redirect to home page but when reload page it logged in? What I am doing wrong? The else condition is for multi-website where I want to logged in user when he logged in on one site.

  • use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue Jul 11, 2017 at 4:47

1 Answer 1


You should use the type singleton for your observer and configure it under the frontent events:

Example for customer login


Namespace_Module_Model_Observer logout singleton


Then in your observer class set/unset your custom session value


public function login()

public function logout()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.