我编写了一个简短的 Perl 脚本,列出了网站的当前 cookie,但不知何故,它报告了 cookiedomain
和expires
空的。我做错了什么还是我误解了 cookie 背后的机制?
我的最终目标是能够通过一个按钮删除现有的 cookie。
该脚本在此处运行,但如果您先访问我的博客可能会有所帮助,因此实际上设置了一些 cookie。这是我的源代码:
use warnings;
use strict;
use CGI::Cookie;
my $table;
my %cookies = CGI::Cookie->fetch;
if ( keys %cookies ) {
$table .= "<table border=\"3\" cellpadding=\"5\">";
$table .= "<caption>COOKIES</caption>";
$table .= "<tr><th>Name</th><th>Domain</th><th>Path</th><th>Expires</th>
<th align=\"left\">Value</th></tr>";
foreach my $cookie ( keys %cookies ) {
$table .= "<tr>";
$table .= "<td>$cookie</td>";
$table .= "<td>" . $cookies{ $cookie }->domain() . "</td>";
$table .= "<td>" . $cookies{ $cookie }->path . "</td>";
$table .= "<td>" . $cookies{ $cookie }->expires . "</td>";
$table .= "<td>" . $cookies{ $cookie }->value . "</td>";
$table .= "</tr>";
}
$table .= "</table>";
}
print "Content-Type: text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<body>\n";
print "$table";
print "</body>\n";
print "</html>\n";
不管我安装脚本的各个网站上的各种 cookie,输出看起来像这样,并且 Domain 和 Expires 始终为空:
+-----------------------------------------------------------------------------------------+
| Name | Domain | Path | Expires | Value |
|---------------+--------+------+---------+-----------------------------------------------|
| bb2_screener_ | | / | | 1379007156 2001:980:1b7f:1:a00:27ff:fea6:a2e7 |
+-----------------------------------------------------------------------------------------+