小饼干cookie

There is a great deal of misinformation about browser cookies, in regards to what their capabilities are and what they are used for.

关于浏览器cookie的功能和用途,存在很多误解。

I find it easiest to compare a cookie to a temporary visa issued by a country with strict internal transit rules for visitors, such as Burma or North Korea. On entering such a country, your visa is stamped with the time and port of entry. The Burmese junta will know which flight you arrived on (and thus where you came from) but will not be aware of any trips made before your flight. Once you have landed, your movement though the country is likely to be tracked, with new entries stamped in your visa when you enter certain provinces or militarily sensitive areas. When you leave, the visa will be given a last stamp that includes the date that you exited the country, and the Burmese will know of your immediate destination, but not of your movement after the aircraft touches down on foreign soil. No other country can read the visa, as it is written in Burmese.

我发现将Cookie与由对缅甸或北朝鲜等有严格内部过境规则的国家签发的临时签证进行比较是最容易的。 进入这样的国家时,您的签证上会标明入境时间和港口。 缅甸军政府会知道您到达的航班(以及您的出发地),但不会知道在飞行之前进行的任何旅行。 登陆后,很可能会追踪您在整个国家的活动,进入某些省份或军事敏感地区时,签证上会标明新条目。 当您离开时,签证将被盖上最后一张邮票,其中包括您离开该国的日期,并且缅甸人将知道您的直达目的地,但不会知道飞机降落在异国土地上之后的动向。 没有其他国家可以阅读以缅甸文书写的签证。

Similarly, cookies are issued per domain. They can contain any information that you, the visitor, provide, and may record actions you take on the site: what pages you visit, how long you stayed, what you clicked on, etc. They can also record where you came from and where you left to (but not actions taken before or after that point). Any information that you enter into a form can be stored inside a cookie (but any information that is personally identifiable should not, as cookies are not secure). Browser and operating system information (browser version, resolution, etc) could also be included. This information is stored on the client, either temporarily (while the browser is running) or permanently, and the data held inside cookies can be checked when the user returns.

同样,每个域也会发布cookie。 它们可以包含您,访问者提供的任何信息,并可以记录您在网站上执行的操作:您访问了哪些页面,停留了多长时间,单击了什么等等。它们还可以记录您来自何处以及来自何处您离开了(但在此之前或之后没有采取任何行动)。 您输入表格中的任何信息都可以存储在cookie内(但是,由于cookie不安全,因此任何个人身份信息都不能存储)。 浏览器和操作系统信息(浏览器版本,分辨率等)也可能包括在内。 此信息可以临时(在浏览器运行时)或永久存储在客户端上,并且当用户返回时可以检查cookie中包含的数据。

There are a few other restrictions on cookies:

Cookie还有其他一些限制:

  • A limit of 20 cookies can be sent from any domain to the client

    最多20个Cookie可以从任何域发送到客户端
  • Cookies can be blocked, modified, copied, or deleted by the client.

    客户端可以阻止,修改,复制或删除Cookies。
  • Cookies should never be used as an absolute means of authentication.

    Cookies绝对不能用作认证的绝对方法。
  • Cookies can contain strings or numbers, to a maximum of 4096 bytes.

    Cookies可以包含字符串或数字,最大为4096个字节。
  • Cookies cannot be read by other domains.

    Cookies不能被其他域读取。
  • Cookies cannot be created in HTML; they must be created, read and modified with a server-side language or JavaScript.

    Cookies不能以HTML格式创建; 必须使用服务器端语言或JavaScript创建,读取和修改它们。

Finally, cookies are threatened long-term by the advent of HTML5's localStorage() feature, which adds database-like structure to client storage of data (as well as being considerably easier to write in JavaScript: writing cookies in pure JavaScript is a pain). This transition will take several years, but it will occur. Cookies will, however, continue to be useful, so they are what we will concentrate on here. (I will cover localStorage() in a later article.)

最后,由于HTML5的localStorage()功能的出现,cookie受到了长期威胁,该功能将类似数据库的结构添加到客户端数据的存储中(而且相当容易用JavaScript编写:用纯JavaScript编写cookie是一件痛苦的事情) 。 这种过渡将花费数年,但是会发生。 但是,Cookie将继续有用,因此我们将在这里重点介绍它们。 (我将在以后的文章中介绍localStorage() 。)

翻译自: https://thenewcode.com/197/Cookies

小饼干cookie

更多推荐