hi all,
i want to develop a shopping cart which uses only sessions to store products their id and prices etc. so, i thought of an idea to store products details in a multidimensional arrays and then into session my idea is like this

array(
[productid1]=>array(
                               [0]=>product name
                               [1]=>productprice
                               [2]=>product image
                                )
[productid2] =>array(
                                [0]=>product name
                                [1]=>productprice
                                [2]=>productimage
                               )
)

and then

$_session['pr']=array();

and we call the session in add to cart page and display cart acording to the productids
we should also able to delete or edit the product details in cart
i think its pretty complicated but i thinks it will reduce database burden when user orders simply but they will not goto to paypal gateway and we will insert temporary orders in database my idea reduses lot of burden on database and after 20 min sessions will expire
i tried every thing if i get little help from the experts here i will able to do it
thanks in advance

Recommended Answers

All 3 Replies

Better yet, why not use cookies? I built my own store once and I used cookies to store user's orders. When they went to finalize their order, it was the inserted into the database. Also, I checked to see if they had cookies enabled, if not then I went ahead and stored the cart in the database temporarily, but most users have cookies enabled.

hi mvied,
thanks for reply i know concepts but i didn`t used cookies earlier in any applications so, iam not that familier programming with cookies if possible will u please sent me the files
it will be the great help.
thank u once again for reply iam scratching my brain to develop this application please help me

Setting cookies is relatively easy.

setcookie("pr", array(), time()+3600);

That should work. Then when someone adds an item to their cart, you can append the next item to the array in the cookie. This would certainly take some time to tweak to get it to work correctly.

I think what I ended up doing was just storing the product's ID's that they had in their cart in my SQL cart_contents table and then storing their cart_id in the cookie. I'm not certain if you can store an array in a cookie since cookies are stored in a $_COOKIE global.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.