Results 1 to 2 of 2

Thread: Creating a shopping cart using PHP cookies

  1. #1
    leo76uk Guest

    Creating a shopping cart using PHP cookies

    Hi everyone,
    I am creating a shopping cart using cookies. The item is post method form which can be $cart = $_REQUEST['item']. I am trying to create an array of requested items using
    <?php
    if ($cart) {
    $cart .= ',' .$_REQUEST['item'];
    } else {
    $cart = $_REQUEST['item'];
    }
    setcookie( "product", $cart,time()+86400);
    ?>
    But not able to retrieve data using the following so the get items from the database.
    <?php
    if ($cart) {
    $items = explode(',',$cart);
    foreach ($items as $item) {
    echo $item;
    }
    }
    ?>
    Can anybody give me the solutions?

  2. #2
    Join Date
    May 2010
    Location
    Riverside, Ca
    Posts
    241
    your cookie is set as "product" so, in PHP you use $_COOKIE['product'] to retrieve the cookie that you saved.
    "The generation of random numbers is too important to be left to chance."

Similar Threads

  1. Need a Shopping Cart for PHP Pro Bid
    By houeis in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 20 Nov 2007, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •