我可以向浏览器发送空 cookie 吗?
can i send empty cookie to browser?
从我的 perl 程序中,我正在发送对 AJAX 调用的响应,如下所示:
...a lot of code...
$| = 1;
print $q->header(-type=>'text/html',-cookie=>$cookie);
my $tt = Template->new({INCLUDE_PATH => $htmlTempletPath});
$tt->process($returnVal,$ttVars)|| die $tt->error();
1;
当用户首次登录时,我设置并发送此 $cookie 作为会话 ID 等以进行身份验证。每当我增加 cookie 的过期时间时,我都会通过 -cookie=> 指令将其发回。
我担心的是,如果 $cookie 变量为空,它如何影响 browser/session 或已经设置的 cookie?还是浏览器默默地忽略 -cookie=> (empty)
请指教。我环顾四周,但没有找到任何帮助。
这在 cookie 的规范文档 RFC6265 中进行了讨论
If the user agent receives a new cookie with the same cookie-name,
domain-value, and path-value as a cookie that it has already stored,
the existing cookie is evicted and replaced with the new cookie.
Notice that servers can delete cookies by sending the user agent a
new cookie with an Expires
attribute with a value in the past.
因此,只有当您发送过期日期已过的 cookie 时,它才会被明确删除。显然,用户 and/or 用户代理仍然可以出于任何其他原因删除您的 cookie。
另见
与 Cookie 相关的 HTTP RFC,https://www.rfc-editor.org/rfc/rfc6265
从我的 perl 程序中,我正在发送对 AJAX 调用的响应,如下所示:
...a lot of code...
$| = 1;
print $q->header(-type=>'text/html',-cookie=>$cookie);
my $tt = Template->new({INCLUDE_PATH => $htmlTempletPath});
$tt->process($returnVal,$ttVars)|| die $tt->error();
1;
当用户首次登录时,我设置并发送此 $cookie 作为会话 ID 等以进行身份验证。每当我增加 cookie 的过期时间时,我都会通过 -cookie=> 指令将其发回。
我担心的是,如果 $cookie 变量为空,它如何影响 browser/session 或已经设置的 cookie?还是浏览器默默地忽略 -cookie=> (empty)
请指教。我环顾四周,但没有找到任何帮助。
这在 cookie 的规范文档 RFC6265 中进行了讨论
If the user agent receives a new cookie with the same cookie-name, domain-value, and path-value as a cookie that it has already stored, the existing cookie is evicted and replaced with the new cookie. Notice that servers can delete cookies by sending the user agent a new cookie with an
Expires
attribute with a value in the past.
因此,只有当您发送过期日期已过的 cookie 时,它才会被明确删除。显然,用户 and/or 用户代理仍然可以出于任何其他原因删除您的 cookie。
另见
与 Cookie 相关的 HTTP RFC,https://www.rfc-editor.org/rfc/rfc6265