How to create a PHP shopping cart and checkout handler?

Help or tell us how a shopping cart is created on online stores, how sessions and cookies are used. I am a novice web programmer, but I just can’t figure it out, since there is little relevant information on the Internet, or rather a lot of garbage…


Answer 1, authority 100%

  1. The user enters the site, the session starts, its unique id is generated;
  2. When purchasing a product, information about the product (product id, quantity) and a unique session id are transferred to the database.
  3. A cleanup should occur upon successful checkout, i.e. all records containing a unique session id are removed from the database, and then the session itself must be destroyed.

Cookies can be used to store information about the order implicitly, and the task of clearing the database also arises, I would not consider this option yet, although it is also not difficult.

Read the book “Programming with PHP and MySQL” by Laura Thompson and Luke Welling for good examples of implementing a store.