View Full Version : cookie problem

04-01-2004, 07:20 AM
hi everyone,

i am stuck in a problem, thanks for ur help. The problem is as follows:

first of all i want to know that can we store multiple values in a single cookie i.e. if we want to store multiple items' id (shopping cart) which the user adds to his/her cart. If yes then how, if no then is it possible to store an array in a cookie.

secondly, if it is possible to store multiple values in a single cookie say - the domainname and an array containing the item ids, and say the cookie name is cart, how can we associate and access these values (domainname and array elements) individually from the a single cookie.

Thirdly, i want to check whether the user's system has cookie set from our domain, how can i check when the user firsts opens/visits our site. Please help me also knowing that supposingly, the user visits the site and adds certain items to his/her cart, then a cookie is set, now when he visits the site again and adds more item to his/her cart, now is is possible to update that cookie with the new items selected or i will have to write another cookie.

If i have to write another cookie how can i destroy the previous cookie.

And finally, please tell the seqence of setting a cookie, do i have to start a session first then give a command setcookie?

Thanx alot for help

04-01-2004, 08:07 AM
Did you check the manual :rolleyes:

5 second answers:
1) use an array --> easier to process
2) use an array --> use a multidimensional array
3) set a cookie + redirect + try to read the cookie. Plenty of examplecode in the usrcomments in above url
4) set a persistent cookie. Read the parts about setting an expiration-pero. Then read te cookie, add new elements to the array and resend the cookie. Each time you change the cookiecontent, it is set again and replaces the older cookie (which also means that the expiratiodate will be pushed forward)
5) read the page from the manual. Has some examplecode and all.