cookies maxvalue

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Since I'm very into cookies lately, I have this question:

Is it possible to have more than 20 cookievalues in your cookiefile? If yes, how?

Thanx in advance,

Shakespeare: onclick || !(onclick)

detox's picture

They have: 571 posts

Joined: Feb 2001

A cookie can hold a maximum of 4096 bytes (4 KB) so however much you can fot into that is the maximum I guess. I would stay away from putting too much into a cookie though..

This is taken from a reference book i have.

Quote:
....suppose you store 2kb of info in a cookie and update that cookie in each request. If you had 100 concurrent users you would create a bandwidth overhead of 4mb over and above the page content....

What it is basically saying is that depending too much on cookies for state management creates huge overheads. You can have a hell of a lot of values in a cookie but if you are servicing a lot of users, it is not worth the cost in bandwidth.

What I would suggest is have a key value in a cookie (if that is what you want to maintain state with) and store the details in a db. That way you are not having to worry about the other issues that come with overuse of cookies.

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Quote: Originally posted by detox

What I would suggest is have a key value in a cookie (if that is what you want to maintain state with) and store the details in a db. That way you are not having to worry about the other issues that come with overuse of cookies.

Actually that is what I have. My question was actually if it is possible to store more than 20 key values in a cookie?
Sorry for making that not clear in the first post.

Shakespeare: onclick || !(onclick)

They have: 601 posts

Joined: Nov 2001

I know that you can only set a maximum of 20 cookies per domain, if that's what you're asking.

If you find yourself reaching this limit, load one cookie with some infromation deliminated by a given field then use your script to deliminate the stored infrormation.

- wil

detox's picture

They have: 571 posts

Joined: Feb 2001

Quote: by JM: My question was actually if it is possible to store more than 20 key values in a cookie?

I actually answered the question in the first line of the reply!

Quote: by D: A cookie can hold a maximum of 4096 bytes (4 KB) so however much you can fit into that is the maximum I guess.

meaning if you can fit 20 key values into a cookie then go ahead, but the limit is 4kb, you should be able to fit in a fair bit. What I was saying was there is a size limit not a maximum number of values limit with cookies.

The rest of the reply was for everyone else who is considering using cookies for state management, and I think there are better ways of doing so.

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Quote:
I know that you can only set a maximum of 20 cookies per domain, if that's what you're asking.

YES! That's what I'm asking, sorry for not being specific enough Shocked

Thanx for the answers! So 20 is the real limit?

Shakespeare: onclick || !(onclick)

They have: 601 posts

Joined: Nov 2001

Yes. As far as I know, anyway. Not sure how updated this information is. Couldn't find any RTF on the subject.

http://www.cookiecentral.com/faq/#4.7

ZDNet also backs up this claim => http://www.zdnet.com/devhead/stories/articles/0,4413,1600620,00.html

What you do then is to load one cookie with loads of different information deliminated by a given field. As in.

user|password|status

And then get your script to split these fields. This saves up on the amount of cookies you use. A little extra work, but the only known workaround I think.

Or you could try fooling the brwoser by sending cookies to different sub-domains, like it says in the URL above.

HTH.

- wil

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Quote:
And then get your script to split these fields

Yeah, that's what I do right now, but I want more Laughing out loud
My cookiefile looks something like this:
Cookie.name1|status1
Cookie.name2|status2
Cookie.name3|status3
etc... until 20.

But I want it to be:
Cookie.name1|status1
Cookie.name2|status2
Cookie.name3|status3
etc... until more than 20.

CONTEXT:
It's the user who defines the value for cookie.name[i] and I let him select his desired status by placing all available cookie.names in a . But I want him to choose out of more than 20 statusses (what's the plural of 'status' Confused ), but it seems like that's pretty impossible.

Gonna look after your 'sub-domain solution' though Smiling

Thanx for the links!

Shakespeare: onclick || !(onclick)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.