Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[网络] 6. 在 HTTP 响应 Header 中,set-cookie 选项有哪些,分别代表什么含义? #943

Open
qiilee opened this issue Feb 24, 2020 · 0 comments

Comments

@qiilee
Copy link
Member

qiilee commented Feb 24, 2020

答案:

Set-Cookie: <cookie-name>=<cookie-value>

  • Expires=<date>
  • Max-Age=<non-zero-digit>
  • Domain=<domain-value>
  • Path=<path-value>
  • Secure
  • HttpOnly
  • SameSite=Strict
  • SameSite=Lax
name = name; // 需要设置cookie的值(name不能使用";"和","号),有多个name值时用";"分隔例如:name1=name1;name2=name2;name3=name3

expires; //cookie的有效期限,格式为:expires="Wdy,DD-Mon-YYYY HH:MM:SS"

path; //设置cookie支持的路径,如果path是一个路径,则cookie对这个目录下的所有文件及子目录生效,例如:path="/cgi-bin/",如果path是一个文件,则cookie指对这个文件生效,例如:path="/cgi-bin/cookie.cgi"

domain; //对cookie生效的域名,例如:domain="gzdzw.51.net"

secure; //如果给出此标志,表示cookie只能通过SSL协议的https服务器来传递,cookie的接收是通过设置环境变量HTTP_COOKIE来实现的,CGI程序可以通过检索该变量获取cookie信息

解析:Cookie 相关的 Http 头

有两个 Http 头部和 Cookie 有关:Set-Cookie 和 Cookie

  • Set-Cookie 由服务器发送,它包含在响应请求的头部中。它用于在客户端创建一个 Cookie
  • Cookie 头由客户端发送,包含在 HTTP 请求的头部中。注意,只有 cookie 的 domain 和 path 与请求的 URL 匹配才会发送这个 cookie。

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant