- I am displaying a products section where there is an add to cart button.
- The user may or may not be logged in.
- Instead of maintaining the cart items in session i maintain it in the database with the current session id as reference.
- After a few navigation or default session time out the session id is regenerated.
- So the current session id does not match with the items added by the user in the database.
- So the total items and amount which i display at the top of the page because zero.
- I had maintained the cart items in the session in the previous projects so i haven’t had any problems.
- I am using code igniter frame work
What should i do to sync the regenerated session id of codeigniter and the session id of the cart items. I am using Native Session in codeigniter rather than the default session management which comes with codeigniter. The reason is the session does not work in IE6 because i hope IE6 is not understanding CI’s headers or some thing like that.
I want to maintain the cart items in database only. What shall i do?
You could use standard PHP sessions – track your own session ID and store that in the DB. Skip the regenerated CI-SessionID entirely.
http://www.php.net/manual/en/session.examples.basic.php
Of course, the downside to this is the sessions aren’t stored as cookies in this manner so when a user’s session expires – they lose their basket. But you can work around this yourself with either a manual cookie store, or force the user to register/login to save basket data.