Skip to content

Cookie

一句话解释

Cookie 是小 片段的 数据那个服务器发送到 浏览器, 哪个是 包含 in subsequent 请求到 相同服务器.

用大白话说

Cookies are small text files that websites store in the browser. The server sends a cookie via the Set-Cookie header, and the browser automatically includes it in every subsequent request to that domain. This makes cookies ideal for session management and authentication.

Cookies have important attributes: HttpOnly (prevents JavaScript access, protecting against XSS), Secure (only sent over HTTPS), SameSite (controls cross-site sending, protecting against CSRF), and 最大值-age/expires (expiration time).

Unlike localStorage, cookies are sent with every HTTP request to the matching domain, which adds overhead. They are limited to about 4KB each. Use cookies for authentication tokens and session IDs; use localStorage for client-only data.

示例

http
Set-Cookie: session_id=abc123; HttpOnly; Secure; SameSite=Strict; Max-Age=3600

// Browser sends this automatically:
Cookie: session_id=abc123

服务器设置 secure, HttpOnly, SameSite Cookie. 浏览器 automatically 包含它 in future 请求.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表