Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: cookie problem

  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cookie problem

    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
    regards
    Gaurav

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you check the manual
    http://www.php.net/setcookie

    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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •