Results 1 to 8 of 8

Thread: Adding multiple items to a cookie (php)

  1. #1
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts

    Adding multiple items to a cookie (php)

    Hi,

    Right i am working on a project where i need a POST value to add to a cookie which is fine as i have just done:

    Code:

    Code:
    setcookie("product", $_POST[product]);
    setcookie("product_select",$_POST[product_select]);
    This works fine, but what i need to do is when this goes to the next section the user can either buy or add another product i need them to be able to add another product to this cookie so on the diplay page it shows all the products they have. Any idea how i am going to do this?

    Cheers,
    Adam

  2. #2
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    Use implode() to store an array of item ids in the cookie and explode() after reading $_COOKIE['product'].

    See http://www.php.net/manual/en/function.implode.php for more info.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  3. #3
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Are you sure you want to use cookies here?
    To err is human. To really foul things up ... you need a computer.

  4. #4
    TiG
    TiG is offline
    Walk a mile in other peoples shoes...
    Join Date
    Jul 2003
    Location
    Questioning it all
    Posts
    6,213
    Thanks
    45
    Thanked
    48 times in 43 posts
    Agree with Yamangman here, why you using cookies to do something like this?.

    Its not the way this should be achieved, cookies aren't shopping baskets and should be limited to what they are storing.

    TiG
    -- Hexus Meets Rock! --

  5. #5
    Senior Member
    Join Date
    Sep 2004
    Posts
    371
    Thanks
    44
    Thanked
    10 times in 9 posts
    I'm not overly experienced with this kind of stuff as I've only done a couple of big projects using PHP but in a project for university I used session variables for my shopping basket. Personally I think that would be much better than using cookies and easier to implement.

  6. #6
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    It depends, cookies are widely used in shopping carts but commonly in conjunction with session vars. The reason being that if the user adds some items to their basket and then goes to browse somewhere else e.g. to review an item or because the shop has third parties they are reselling through, then session vars may not be viable and they aren't persistent.

    In short, use both, first check for session vars and if they don't exist then check for cookies. There should be nothing in the cookie that is a security risk, just some product IDs. If you don't want to take the risk of multiple people sharing a PC then put a user key of some sort in the cookie, an md5 hash should of the username or something similar should be fine

  7. #7
    Web Extraordinaire
    Join Date
    Aug 2004
    Posts
    301
    Thanks
    0
    Thanked
    0 times in 0 posts
    Thank you for your replys everyone.

    Basically it is for only one product the product is a photo. The idea is people can upload their photo and they chose from different sizes etc and that will be sent to them on a canvas when the buy.

    The customer can buy multiple images but will essentially be the same product just a different sizes and image for each one that is why i am using cookies to do this.

  8. #8
    NOT Banned
    Join Date
    Jan 2007
    Posts
    5,905
    Thanks
    412
    Thanked
    278 times in 253 posts
    Quote Originally Posted by TiG View Post
    Agree with Yamangman here, why you using cookies to do something like this?.

    Its not the way this should be achieved, cookies aren't shopping baskets and should be limited to what they are storing.

    TiG
    how else can you store the basket? reading the basket from the server is worse. storing it in mysql is worse. puts more load on the server and what about all the people who visit it. look at scan and ebuyer and dabs and every other shop they all use cookies to store your basket. for scan I add some today only's and next week i'll still have them there. only if i empty cache or clear cookies then it goes.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Part Shipment Option for Pre-Order Items - Now Live !
    By Chris P in forum SCAN.care@HEXUS
    Replies: 0
    Last Post: 22-02-2007, 10:55 AM
  2. Unhappy with poor customer experience
    By FreeFrank in forum SCAN.care@HEXUS
    Replies: 3
    Last Post: 14-02-2007, 04:40 PM
  3. Patch 1.4 Released
    By ERU in forum PC
    Replies: 60
    Last Post: 26-11-2006, 05:43 PM
  4. Replies: 2
    Last Post: 19-11-2005, 11:58 AM
  5. adding php to w2k iis5?
    By joshwa in forum Software
    Replies: 13
    Last Post: 29-11-2003, 02:08 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
  •