Jump to content

Cookie size problem with shopping cart


DavidT

Recommended Posts

Hi everybody.

I had been using database to store data from a shopping cart, but now I am trying to create a simpler version using cookies, so that the user doesn‘t need to previously log in.

The problem is that after adding a few element I found out the limit size in cookies, so I just got an error page saying: Size of a request header field exceeds server limit.

 

Should I conclude that using cookies for a shopping cart is simply a bad idea, or is there some way to solve this problem?

If it is a bad idea, how should I project my shopping cart instead?

 

Thank you very much!

Link to comment
Share on other sites

Using cookies to store shopping cart data is a pretty standard practice. If you are running into problems then you are likely storing way more data than you need to. For a standard shopping cart you would just need a simple array such as

$_COOKIE['cart'] (
    [2] => 10,
    [4] => 1,
    [9] => 3,
    [12] => 1
)

 

where the numeric index is the product id and the value is the quantity. It might require a more complex format if the products can have more variables such as size and color, but not to the extent that you would have a problem with the cookie size.

Link to comment
Share on other sites

Well I was indeed saving the whole order array in the cookie (so I had the keys code, value and caption, with this one relatively large), to have easy access to all the data. I’ll save only the code then, and retrieve other data only when necessary.

 

Thank you for your answer!

Link to comment
Share on other sites

Well I was indeed saving the whole order array in the cookie (so I had the keys code, value and caption, with this one relatively large), to have easy access to all the data. I’ll save only the code then, and retrieve other data only when necessary.

 

Thank you for your answer!

 

Right, you should ONLY store the minimum data necessary in order to identify the product. Things like descriptions, price, etc. can change. Therefore, you always want to get the freshest data using the ID.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.