views:

2005

answers:

2

I'm wondering what the maximum size of a web browser's cookie's key is. I know the maximum size of a cookie is 4KB, but does the key have a limitation as well?

Thanks!

+2  A: 

A cookie key(used to identify a session) and a cookie are the same thing being used in different ways. So the limit would be the same. According to Microsoft its 4096 bytes.

MSDN

cookies are usually limited to 4096 bytes and you can't store more than 20 cookies per site. By using a single cookie with subkeys, you use fewer of those 20 cookies that your site is allotted. In addition, a single cookie takes up about 50 characters for overhead (expiration information, and so on), plus the length of the value that you store in it, all of which counts toward the 4096-byte limit. If you store five subkeys instead of five separate cookies, you save the overhead of the separate cookies and can save around 200 bytes.

cgreeno
Incidentally, just because you have about 4KB of browser cookie storage to play with you ought to seriously consider whether that's a good idea or not.
Chris Lively
couldn't agree more!
cgreeno
+3  A: 

Actually, RFC 2965, the document that defines how cookies work, specifies that there should be no maximum length of a cookie's key or value size, and encourages implementations to support arbitrarily large cookies. Each browser's implementation maximum will necessarily be different, so consult individual browser documentation.

See section 5.3, "Implementation Limits", in the RFC here.

John Feminella