Ash Ketchum
Ash Ketchum

Reputation: 21

PHP shopping cart with cookies

I need to do for homework with PHP a list of two products and when i click on anyone of them , the selected product goes to a shopping cart but using COOKIES.

I don't know how to use cookies properly maybe you can help me.

I just need to click in the button/input of one product and then goes listed in a cookie or something like that.

Then if for example i click two times in product A and one time in product B, the cookies takes that info and shows me:

A product x2

B product x1

Ty!!

Upvotes: 0

Views: 1124

Answers (1)

Balaji Rajendran
Balaji Rajendran

Reputation: 367

        <?php
        //set cookie
        $cookie = "product detail";
        $expire=time()+60*60*24*30;
        setcookie("product_id", $cookie, $expire);

       //retrieve detail
       if($product_id == "product id"){
        $name = $_COOKIE["product_id"];
         }
        ?>

Upvotes: 0

Related Questions