简体   繁体   English

允许的最大 cookie 数量

[英]Maximum number of cookies allowed

As far as Google searches tell me, the maximum allowed number of cookies depends very much on the browser, however I cannot find any recent data as to how much cookies are allowed on modern browsers.据谷歌搜索告诉我,允许的最大 cookie 数量在很大程度上取决于浏览器,但是我找不到任何关于现代浏览器允许多少 cookie 的最新数据。

I need to store a somewhat large number of user preferences in cookies (for not-yet-registered users), so what would be the best way of doing that?我需要在 cookie 中存储大量用户首选项(对于尚未注册的用户),那么最好的方法是什么? (Also, those cookies would be accessed both via javascript client-side and php server-side) (此外,这些 cookie 将通过 javascript 客户端和 php 服务器端访问)

From the rfc :rfc

  • at least 300 cookies至少 300 个饼干

  • at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)每个 cookie 至少 4096 字节(根据 Set-Cookie 标头的语法描述中构成 cookie 非终结符的字符的大小来衡量)

  • at least 20 cookies per unique host or domain name每个唯一的主机名或域名至少有 20 个 cookie

Those are minimum requirements.这些是最低要求。 The IE6 team didn't get that. IE6 团队没有意识到这一点。 Everything else is highly browser-specific.其他一切都是高度特定于浏览器的。 You'd better write a test-platform to test each browser.您最好编写一个测试平台来测试每个浏览器。 Test the maximum size and number with little incremental steps (and check if they still are readable).以少量增量步骤测试最大大小和数量(并检查它们是否仍然可读)。

Also, I seem to remember apache has a problem with huges numbers of cookies.另外,我似乎记得 apache 有大量 cookie 的问题。 Can't remember where i've seen that though.不记得我在哪里看到过。

Here is a little cookie-testing script: http://krijnhoetmer.nl/stuff/javascript/maximum-cookies/这是一个小 cookie 测试脚本: http : //krijnhoetmer.nl/stuff/javascript/maximum-cookies/

The best way would be to not store them in a cookie at all.最好的方法是根本不将它们存储在 cookie 中。

Store them in a database, and store the DB key in the cookie.将它们存储在数据库中,并将 DB 键存储在 cookie 中。 If it's just a few preferences then security isn't much of an issue.如果只是一些偏好,那么安全性就不是什么大问题。

Don't forget that cookies will be sent with every request - if you have 2kb of cookie data and load 10 images on a page, that's an extra 22kb of data.不要忘记 cookie 将随每个请求一起发送 - 如果您有 2kb 的 cookie 数据并在页面上加载 10 张图像,那么这额外的 22kb 数据。

Number of Cookies:饼干数量:

  • Chrome 9 allowed 180 cookies per domain Chrome 9 允许每个域 180 个 cookie
  • Firefox 3.6.3 allowed 50 cookies per domain Firefox 3.6.3 允许每个域 50 个 cookie
  • Internet Explorer 8 allowed 50 cookies per domain Internet Explorer 8 允许每个域 50 个 cookie
  • Opera 10 and 9 allowed 30 cookies per domain Opera 10 和 9 允许每个域 30 个 cookie

Cookie size Limits (4096 bytes): Cookie 大小限制(4096 字节):

  • Firefox and Safari allow cookies with up to 4097 characters, that's 4096 for the name and value and one for the equals sign. Firefox 和 Safari 允许最多包含 4097 个字符的 cookie,其中 4096 个用于名称和值,1 个用于等号。
  • Opera allows cookies with up to 4096 characters, which is for the name, value, and equals sign. Opera 允许最多 4096 个字符的 cookie,用于名称、值和等号。
  • Internet Explorer allows cookies with up to 4095 characters, which is for the name, value and, equals sign. Internet Explorer 允许最多 4095 个字符的 cookie,用于名称、值和等号。

SRC: http://webdesign.about.com/od/cookies/f/cookies-per-domain-limit.htm and http://www.nczonline.net/blog/2008/05/17/browser-cookie-restrictions/ SRC: http : //webdesign.about.com/od/cookies/f/cookies-per-domain-limit.htmhttp://www.nczonline.net/blog/2008/05/17/browser-cookie-限制/

I looked into this today, if you want to support most browsers, then don't exceed 50 cookies per domain, and don't exceed 4095 bytes per domain (ie total size of all cookies <= 4095 bytes)我今天研究了这个,如果你想支持大多数浏览器,那么每个域不要超过 50 个 cookie,每个域不要超过 4095 个字节(即所有 cookie 的总大小 <= 4095 个字节)

To read more about it, here is the test page and results .要阅读有关它的更多信息,这里是测试页和结果

IIRC, it's 20 for the majority general, more for some, and 10 for one particular browser (again IIRC, IE5.5?). IIRC,对于大多数人来说是 20,对于某些人来说更多,而对于一种特定的浏览器(又是 IIRC,IE5.5?),它是 10。 Up to 10 is considered a safe number.最多 10 被认为是一个安全数字。

You don't really need more than one anyway - just use one to store an ID client-side and store everything you need stored server-side against that same ID.无论如何,您实际上并不需要多个 - 只需使用一个来存储客户端的 ID,并根据相同的 ID 存储您需要在服务器端存储的所有内容。 Apart from anything else, the less data you leave the the client, the less there is for them to remove/corrupt/hack/etc.除此之外,您离开客户端的数据越少,他们删除/损坏/破解/等的次数就越少。

不确定从他们的角度来看这有多大意义,但我见过一些网站设置了 450 多个 cookie 并向140 多个独特的第三方域报告

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 允许的Cookie数量限制? -err_spdy_protocol_error - Limit on number of cookies allowed? - err_spdy_protocol_error 如何设置Wordpress中任何特定自定义帖子类型允许的最大帖子数 - How to set maximum number of posts allowed for any specific custom post type in Wordpress {"status":true,"message":"批量消息数 (1016) 超过允许的最大值 (1000)\n"} - {"status":true,"message":"Number of messages on bulk (1016) exceeds maximum allowed (1000)\n"} 如何指定输入元素中允许的最大字符数-设置maxlength属性是否足够? - How to specify a maximum number of characters allowed in an input element - Is setting a maxlength attribute enough? 如果我超过最大 cookie 的限制会发生什么 - What happens if I exceed the limit of maximum cookies MySQL允许使用的最大连接数-编码错误? - MySQL Maximum Connections Allowed Used - Coding Error? PHP如何查找允许的最大POST数据? - PHP How to find maximum allowed POST data? DOMDocument :: schemaValidate()超出允许的最大长度&#39;255&#39; - DOMDocument::schemaValidate() exceeds the allowed maximum length of '255' PHP代码优化,最大允许内存错误 - PHP code optimize, Maximum allowed memory error 允许的最大PHP-Postgres准备语句? - Maximum allowed PHP-Postgres prepared statements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM