Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- session_start();
- //Check if $_SESSION['cart] exists
- if (!isset($_SESSION['cart'])) {
- //initiate cart as empty array
- $_SESSION['cart'] = [];
- }
- if (isset($_POST['add'])) {
- //add product id to session cart
- $_SESSION['cart'][$_POST['add']] =1;
- }
- else if (isset($_POST['remove'])) {
- //remove product id from session cart
- unset($_SESSION['cart'][$_POST['remove']]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement