I’ve been playing with the paypal html code and have been working on a shopping cart, I don’t want to use a premade cart system.
So far my approach has been to store the items added to a cart in an array. I want to store it in a cookie really but don’t know how to update the cookie each time a new item is added.
Any general advice about how to go about it would be great.
Typically, you’ll need something on the server side (PHP?) to store such information. In PHP you would do
session_start()and it would give a session number cookie to the browser, which would identify it to the server from that point forward (until it expires). Then you can use$_SESSION[]to store information regarding the cart, your customer, etc.If you’re not going to use server-side persistence, then you’ll have to create lots of messy cookies or pass stuff back and forth in the URL.
Regardless of whether you do pure client-side persistence or server-side, you’ll want to check and validate all data once submitted to the server because it can be manipulated by the user before submission. So prices, discounts can be changed and sent by the user. Check ’em before accepting them at the server.