Session in Magento can be implemented and managed by one of the following way
- File system.
- Database.
- Memcached.
- 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?
- Add.
Syntax to add Magento sessionMage::getSingleton(‘{{type}}/session’) ->set{{SESSION_NAME}}(‘VALUE’);For e.g.
Mage::getSingleton(‘core/session’) ->setCompanyName(‘Trimantra’);Here type can be core, customer, checkout… Etc.
- Retrieve.
Syntax to get/retrieve Magento sessionMage::getSingleton(‘{{type}}/session’) ->get{{SESSION_NAME}}();For e.g.
Mage::getSingleton(‘core/session’) ->getCompanyName ();Here type can be core, customer, checkout… Etc.
- Delete / Unset Session.
Syntax to delete / unset Magento sessionMage::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