Session and cookies are not removing in MagentoErratic cookie-related login problemExclude a specific categoryHow to Set Session Cookie Based on Query-String Param in Magentocustomer/session isLoggedIn() returns falsegetVisitorData() returns NULL on Category Page only in magento-1.9.2.2Sharing Users and Cart in website with different storeviewsSetting Magento Session CookiesSimple Observer not firing on eventMagento model not fetching dataMagento 2 : Unable to save data in Sessions with Cache enabled

Why can't RGB or bicolour LEDs produce a decent yellow?

Why was the Ancient One so hesitant to teach Dr. Strange the art of sorcery?

Will change of address affect direct deposit?

Why was this sacrifice sufficient?

Renting a house to a graduate student in my department

Exception propagation: When to catch exceptions?

Was there a contingency plan in place if Little Boy failed to detonate?

Is there a faster way to calculate Abs[z]^2 numerically?

Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?

Why do unstable nuclei form?

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech?

How Car Rear View Mirrors Work

Is it a bad idea to replace pull-up resistors with hard pull-ups?

about the word 地図

What does it mean with the ask price is below the last price?

51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?

How to select certain lines (n, n+4, n+8, n+12...) from the file?

Is the schwa sound consistent?

What is the best way for a skeleton to impersonate human without using magic?

Why does the Earth follow an elliptical trajectory rather than a parabolic one?

How do I get past a 3-year ban from overstay with VWP?

Can you book a one-way ticket to the UK on a visa?

Why use steam instead of just hot air?

How could we transfer large amounts of energy sourced in space to Earth?



Session and cookies are not removing in Magento


Erratic cookie-related login problemExclude a specific categoryHow to Set Session Cookie Based on Query-String Param in Magentocustomer/session isLoggedIn() returns falsegetVisitorData() returns NULL on Category Page only in magento-1.9.2.2Sharing Users and Cart in website with different storeviewsSetting Magento Session CookiesSimple Observer not firing on eventMagento model not fetching dataMagento 2 : Unable to save data in Sessions with Cache enabled






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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 :



 <customer_logout>
<observers>
<customer_is_loggedout_observer>
<type>model</type>
<class>Easylife_Sales_Model_Observer</class>
<method>customerLogout</method>
</customer_is_loggedout_observer>
</observers>
</customer_logout>
<controller_action_predispatch>
<observers>
<customer_is_logged_in_observer>
<class>Easylife_Sales_Model_Observer</class>
<method>setHandle</method>
</customer_is_logged_in_observer>
</observers>
</controller_action_predispatch>
<sales_quote_collect_totals_before>


And PHP code is in observer :



<?php

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'));
if($session->isLoggedIn())

$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 )

Mage::getSingleton('customer/session')->loginById(Mage::getModel('core/cookie')->get('loginuser'));





public function customerLogout(Varien_Event_Observer $observer)


if (isset($_COOKIE['loginuser']))
unset($_COOKIE['loginuser']);
setcookie('loginuser', null, -1, '/');

Mage::getSingleton('checkout/session')->unsetAll();
$cookieName = 'loginuser';
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->unsetAll();
$session->clear();

//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.










share|improve this question
























  • use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue

    – Minesh Patel
    Jul 11 '17 at 4:47

















0















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 :



 <customer_logout>
<observers>
<customer_is_loggedout_observer>
<type>model</type>
<class>Easylife_Sales_Model_Observer</class>
<method>customerLogout</method>
</customer_is_loggedout_observer>
</observers>
</customer_logout>
<controller_action_predispatch>
<observers>
<customer_is_logged_in_observer>
<class>Easylife_Sales_Model_Observer</class>
<method>setHandle</method>
</customer_is_logged_in_observer>
</observers>
</controller_action_predispatch>
<sales_quote_collect_totals_before>


And PHP code is in observer :



<?php

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'));
if($session->isLoggedIn())

$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 )

Mage::getSingleton('customer/session')->loginById(Mage::getModel('core/cookie')->get('loginuser'));





public function customerLogout(Varien_Event_Observer $observer)


if (isset($_COOKIE['loginuser']))
unset($_COOKIE['loginuser']);
setcookie('loginuser', null, -1, '/');

Mage::getSingleton('checkout/session')->unsetAll();
$cookieName = 'loginuser';
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->unsetAll();
$session->clear();

//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.










share|improve this question
























  • use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue

    – Minesh Patel
    Jul 11 '17 at 4:47













0












0








0








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 :



 <customer_logout>
<observers>
<customer_is_loggedout_observer>
<type>model</type>
<class>Easylife_Sales_Model_Observer</class>
<method>customerLogout</method>
</customer_is_loggedout_observer>
</observers>
</customer_logout>
<controller_action_predispatch>
<observers>
<customer_is_logged_in_observer>
<class>Easylife_Sales_Model_Observer</class>
<method>setHandle</method>
</customer_is_logged_in_observer>
</observers>
</controller_action_predispatch>
<sales_quote_collect_totals_before>


And PHP code is in observer :



<?php

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'));
if($session->isLoggedIn())

$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 )

Mage::getSingleton('customer/session')->loginById(Mage::getModel('core/cookie')->get('loginuser'));





public function customerLogout(Varien_Event_Observer $observer)


if (isset($_COOKIE['loginuser']))
unset($_COOKIE['loginuser']);
setcookie('loginuser', null, -1, '/');

Mage::getSingleton('checkout/session')->unsetAll();
$cookieName = 'loginuser';
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->unsetAll();
$session->clear();

//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.










share|improve this question
















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 :



 <customer_logout>
<observers>
<customer_is_loggedout_observer>
<type>model</type>
<class>Easylife_Sales_Model_Observer</class>
<method>customerLogout</method>
</customer_is_loggedout_observer>
</observers>
</customer_logout>
<controller_action_predispatch>
<observers>
<customer_is_logged_in_observer>
<class>Easylife_Sales_Model_Observer</class>
<method>setHandle</method>
</customer_is_logged_in_observer>
</observers>
</controller_action_predispatch>
<sales_quote_collect_totals_before>


And PHP code is in observer :



<?php

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'));
if($session->isLoggedIn())

$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 )

Mage::getSingleton('customer/session')->loginById(Mage::getModel('core/cookie')->get('loginuser'));





public function customerLogout(Varien_Event_Observer $observer)


if (isset($_COOKIE['loginuser']))
unset($_COOKIE['loginuser']);
setcookie('loginuser', null, -1, '/');

Mage::getSingleton('checkout/session')->unsetAll();
$cookieName = 'loginuser';
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->unsetAll();
$session->clear();

//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.







magento-1.9 cookie logout customer-session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 15 '18 at 21:06









Greg

1,60911135




1,60911135










asked Feb 12 '15 at 7:35









AddaAdda

57214




57214












  • use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue

    – Minesh Patel
    Jul 11 '17 at 4:47

















  • use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue

    – Minesh Patel
    Jul 11 '17 at 4:47
















use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue

– Minesh Patel
Jul 11 '17 at 4:47





use Mage::getModel('core/cookie') to delete cookie as well. might be issue with domain name and http only flag issue

– Minesh Patel
Jul 11 '17 at 4:47










1 Answer
1






active

oldest

votes


















0














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



Example for customer login



use








Namespace_Module_Model_Observer
logout
singleton




 <customer_login>
<observers>
<your_unqiue_event_name1>
<class>Namespace_Module_Model_Observer</class>
<method>login</method>
<type>singleton</type>
</your_unqiue_event_name1>
</observers>
</customer_login>
</events>




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



in



public function login()

.....
Mage::getSingleton('customer/session')->setMyValue($myValue);
.....


public function logout()

.....
Mage::getSingleton('customer/session')->unsMyValue();
.....






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f55489%2fsession-and-cookies-are-not-removing-in-magento%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














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



    Example for customer login



    use








    Namespace_Module_Model_Observer
    logout
    singleton




     <customer_login>
    <observers>
    <your_unqiue_event_name1>
    <class>Namespace_Module_Model_Observer</class>
    <method>login</method>
    <type>singleton</type>
    </your_unqiue_event_name1>
    </observers>
    </customer_login>
    </events>




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



    in



    public function login()

    .....
    Mage::getSingleton('customer/session')->setMyValue($myValue);
    .....


    public function logout()

    .....
    Mage::getSingleton('customer/session')->unsMyValue();
    .....






    share|improve this answer





























      0














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



      Example for customer login



      use








      Namespace_Module_Model_Observer
      logout
      singleton




       <customer_login>
      <observers>
      <your_unqiue_event_name1>
      <class>Namespace_Module_Model_Observer</class>
      <method>login</method>
      <type>singleton</type>
      </your_unqiue_event_name1>
      </observers>
      </customer_login>
      </events>




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



      in



      public function login()

      .....
      Mage::getSingleton('customer/session')->setMyValue($myValue);
      .....


      public function logout()

      .....
      Mage::getSingleton('customer/session')->unsMyValue();
      .....






      share|improve this answer



























        0












        0








        0







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



        Example for customer login



        use








        Namespace_Module_Model_Observer
        logout
        singleton




         <customer_login>
        <observers>
        <your_unqiue_event_name1>
        <class>Namespace_Module_Model_Observer</class>
        <method>login</method>
        <type>singleton</type>
        </your_unqiue_event_name1>
        </observers>
        </customer_login>
        </events>




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



        in



        public function login()

        .....
        Mage::getSingleton('customer/session')->setMyValue($myValue);
        .....


        public function logout()

        .....
        Mage::getSingleton('customer/session')->unsMyValue();
        .....






        share|improve this answer















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



        Example for customer login



        use








        Namespace_Module_Model_Observer
        logout
        singleton




         <customer_login>
        <observers>
        <your_unqiue_event_name1>
        <class>Namespace_Module_Model_Observer</class>
        <method>login</method>
        <type>singleton</type>
        </your_unqiue_event_name1>
        </observers>
        </customer_login>
        </events>




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



        in



        public function login()

        .....
        Mage::getSingleton('customer/session')->setMyValue($myValue);
        .....


        public function logout()

        .....
        Mage::getSingleton('customer/session')->unsMyValue();
        .....







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 '16 at 21:36









        Marius

        169k28324695




        169k28324695










        answered Nov 9 '16 at 19:44









        StijnStijn

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f55489%2fsession-and-cookies-are-not-removing-in-magento%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form