I am currently developing a simple shopping cart using PHP & HTML. I've been having troubles with using the SESSIONS in Php like: Sessions not continuing when I switch pages even though I called the session_start() at the top of  every page.Is it a better approach to use sessions in keeping track of a clients cart?My requirements are as follows: Keep track of users cart when user is switching pages.Save users cart to database when the user proceeds to check out.Clear users cart(session) when it has been idle for 30 minutes.
Shopping cart in PHP : Sessions or Database?
php;html;mysql;session
Either way you will want to use sessions for persisting data through the customer experience since you're ultimately working across a stateless protocol. If I have to implement a database then I go ahead and move the sessions to the database (the client may still need a cookie depending on how you decide to go about that.) As for the cart, as soon as I had to use a database, I tended to move it to the database as well. When I'd use a framework like CodeIgniter then I'd let it make the call unless I had a compelling reason to do otherwise. Since to meet #2 you'll have to design the db to store a cart at checkout, then you may as well store it in the db across the user's experience. I'd take a look at this as well: https://stackoverflow.com/questions/12569568/shopping-cart-persistence-session-or-browser-cookie