I know Magento has following core functions for session and cookie handling:


When does Magento set Cookies and when PHP Sessions? What are the use cases?

I'm a bit confused, because I know Magento stores the cart information in Mage::getSingleton('checkout/session') and the status of the user in Mage::getSingleton('customer/session'). But the checkout session doesn't seem to be a session, but a cookie instead. Because when I close the browser and re-open the page the items are still in the cart.

Does that mean, that the checkout/sessionmodel sets cookies and not the global $_SESSION variable?

2 Answers 2


No, that means that sessions are persisted with a cookie, which contains the ID of the session. The only alternative in PHP is a URL parameter like ?SID=d41d8cd98f00b204e9800998ecf8427e where d41d8cd98f00b204e9800998ecf8427e is the session ID.

In Short, session data are stored on the server but since HTTP is stateless, a cookie or parameter with the session id is necessary to identify the right session.

Magento sets two session cookies, adminhtml for the backend and frontend for the frontend. Session models like 'checkout/session' store their data in a "namespace", i.e. $_SESSION['checkout'].

Session-unrelated cookies that Magento sets, are for example the store cookie that remembers, which store view you currently browse.


Mage::getSingleton('checkout/session') Saves all data you selected in Flats tables example. sales_flat_quote sales_flat_quote_address and more.

What is this: every customer at its first visit receives a quote_id which is unique and a relation with data in others quote tables and it is persistent that's why you always can see your Cart. This data everytime you change cart, data and something in your checkout form before you finish an order. After you finish your order all quote data is got and saved in order tables ep. sales_order_items and your quote data gets a disable status. This happens everytime you make and order.

Mage::getSingleton('customer/session') has your customer data when you are logged.

I hope this makes sense for you. This can be easier to explain by talking. The way than magento manage his data is complex and really good distributed but once you understand how data is manage and how to manipulate it. You did it Esasy cake magento.


this is the way to get quote_id by session

   $session        = Mage::getSingleton('checkout/session');
   $quote_id       = $session->getQuoteId();
  • So is this quote_id saved in a session or cookie?
    – Rouzbeh
    Commented Mar 2, 2015 at 12:14
  • in Session. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users.
    – Duarte
    Commented Mar 2, 2015 at 12:25
  • That's exactly what I don't understand. The session does expire when I close the browser. But how does Magento still remember the quote_id and thereby cart items when re-opening the browser?
    – Rouzbeh
    Commented Mar 2, 2015 at 12:32
  • Your session stores your IP and when you come back Magento use it to get your quote_id and Magic you can see your Cart again. Logged and not logged user have a quote_id Quote Data doesn't expire
    – Duarte
    Commented Mar 2, 2015 at 12:37
  • 1
    Ok, check this. 1)Not logged: You added 3 products to Cart then data is saved in sales_flat_quote if you remove cookies and cache. Your data is lost and your Cart will be empty. So not logged users their token is based in cookies and cache. 2)Logged: Same 3 products in Cart And you clear Browser cookies and cache. you get logout but when you log in 3 products still there. All this magic is managed by quote
    – Duarte
    Commented Mar 2, 2015 at 16:12

Your Answer

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

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