Take the 2-minute tour ×

I am coding a E-commerce website/admin interface for a client. They are doing some B2B so they want the cart to be saved/loaded from database so if the user close his browser and reopen it the cart is intact.

The application is using the Zend Framework and I've been looking to the Zend_Session_SaveHandler_DbTable. So I can save the session in the database easily what about the reverse case I want to load the database in session.

Also it would be nice if can load that cart items only when the users reopen the browser not on every page since it would have some performance impact.

Any advices ?

Kind of sub question: I suppose Zend_Session is using $_SESSION so everything is based on the php session id, is there any possibilities to change what it is using has id.

I am thinking of generating my unique id and pushing this to client with cookies.

NOTE 2: the user is able to build some cart not being logged so I cannot rely on the login process ....

share|improve this question
this might be a duplicate of stackoverflow.com/questions/854092/… –  CheeseConQueso Feb 19 '10 at 22:00
add comment

2 Answers

up vote 1 down vote accepted

The first thing you need to do is work out how to make sessions persist beyond the user closing their browser. Check the Zend_Session configuration part of the manual:


see the part on the 'remember_me_seconds' option. Once you have this working, anything you store in the session will be available when the user comes back another day.

As for storing the cart in the session, I would suggest creating a 'Cart' class which contains this information. You could then either store the whole object in the session or store the data in a 'carts' table in your database and merely store the ID of the cart in the user's session. Then on subsequent visits you just have to check for the existence of the ID and load the Cart up if it's present.

share|improve this answer
@Tim: thanks for the answer, actually after few hour posting this question I found about the rememberMe feature by myself and it did the work. –  RageZ Feb 26 '10 at 2:13
add comment

I had same problem as you when I wanted to store column settings for grid before two weaks. And I didnt have whole session in DB. I just check session if there is something in the cart. If there is nohing in session, load from db. And on every change of basket save to db of course.

And I used serialized array from Session_Namespace::to_array() method. not whole Session_Namespace because of I cant load it back.

You can use flag which eill tell you, that you try load from db once, for instance that there is no cart in db same in session and you dont want try to load cart every request.

share|improve this answer
add comment

Your Answer


