Request a Quote

How to manage Session in Magento

How to manage Session in Magento

Session in Magento can be implemented and managed by one of the following way

  1. File system.
  2. Database.
  3. Memcached.
  4. tmpfs Filesystem.

Out of these 4 options, 2 options are available while installing Magento from which File system is by default selected.

How to Add, Retrieve and Delete (unset) a Magento session?

  1.  Add.
    Syntax to add Magento session

    Mage::getSingleton(‘{{type}}/session’) ->set{{SESSION_NAME}}(‘VALUE’);

    For  e.g.

    Mage::getSingleton(‘core/session’) ->setCompanyName(‘Trimantra’);

    Here type can be core, customer, checkout… Etc.

  2. Retrieve.
    Syntax to get/retrieve Magento session

    Mage::getSingleton(‘{{type}}/session’) ->get{{SESSION_NAME}}();

    For  e.g.

    Mage::getSingleton(‘core/session’) ->getCompanyName ();

    Here type can be core, customer, checkout… Etc.

  3. Delete / Unset Session.
    Syntax to delete / unset Magento session

    Mage::getSingleton(‘{{type}}/session’) ->uns{{SESSION_NAME}}();

    For  e.g.

    Mage::getSingleton(‘core/session’) ->unsCompanyName ();

    Here type can be core, customer, checkout… Etc.

Rakesh Gangani
Magento  Developer

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2015 Trimantra Software Solution LLP- Software Outsourcing Company India. All rights reserved.