1 Replies - 359 Views - Last Post: 27 July 2011 - 02:40 AM

#1 aklo   User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 233
  • Joined: 23-January 09

Cookies only 1 name value pair?

Posted 27 July 2011 - 02:35 AM

From what I know, cookies only can store a name value pair.

Using javascript:

document.cookies = username="hello";
it cannot be
document.cookies = username="hello"; font="small"; background="blue";

So assuming my site will let users store their background color and font size preference means I will have to
create 2 cookies?

So for every "custom" user preference there will be one cookies associated?

Or are these info store in a database binded with the user login.

Is This A Good Question/Topic? 0
  • +

Replies To: Cookies only 1 name value pair?

#2 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Cookies only 1 name value pair?

Posted 27 July 2011 - 02:40 AM

You can by all means use a custom format for your cookie data, a good choice would be JSON. Within PHP you can use json_encode to create this, and with Javascript you can just read it out and eval it (in a perfect world, don't actually do this, but there's resources on how to do it safely ;)).

This way you have multiple values in a single cookie - win :)

This post has been edited by RudiVisser: 27 July 2011 - 02:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1