DavidT Posted April 6, 2012 Share Posted April 6, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/260469-cookie-size-problem-with-shopping-cart/ Share on other sites More sharing options...
Psycho Posted April 6, 2012 Share Posted April 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260469-cookie-size-problem-with-shopping-cart/#findComment-1335068 Share on other sites More sharing options...
DavidT Posted April 6, 2012 Author Share Posted April 6, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/260469-cookie-size-problem-with-shopping-cart/#findComment-1335100 Share on other sites More sharing options...
Psycho Posted April 6, 2012 Share Posted April 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260469-cookie-size-problem-with-shopping-cart/#findComment-1335102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.