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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Using arrays in cookies?

    Is there a way to successfully use arrays in cookies? Like I wanna add to the cookie but it doesn't seem to work..

    Tried doing this but it doesn't seem to work..

    PHP Code:
    setcookie("cookiename[]"somedatatime() + 15768000'/''.domain.com'); 
    Any ideas??

    Thanks!

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Serialize the array.

    http://www.php.net/serialize

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Could u give me an example? I'm not sure I'm understanding it correctly.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    $array = array('one''two' 'tacos' => 'three');
    $somedata serialize($array);
    setcookie("cookiename"$somedatatime() + 15768000'/''.domain.com'); 

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Hmm.... but how would you use that to add to an exisiting cookie?

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm not sure, I don't work with cookies enough to tell you.

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Oh ok... thx 4 the help anyways!

  • #8
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You should just watch out for one thing. The serialized arrays carry their types of values unlike _POST/_GET (where everything is a string) so you might want to check if the types are correct.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

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