0

我在设置和获取 cookie 数据时遇到问题。

当我调用以下方法时:

%cookies = CGI::Cookie->fetch;

并使用 Data::Dumper 打印出散列:

print Dumper(%cookies);

我之前创建的 Cookie:

$sessioncookie = CGI::Cookie->new(-name=>'SID', -value=>"$sid", -expires=>'+1M', -path=>'/member/');
print $cgi->header(-cookie=>$sessioncookie);

不会出现在输出中。但它显示在我的浏览器 cookie 列表中!所有值都已设置,看起来就像一个普通的 cookie。但实际上不可能。

有人知道我做错了什么。检索 cookie 数据是否有严格的顺序?

我也用 cgi.pm 提供的方法试过了,但也没有用。

请帮我!

4

1 回答 1

1

As per the help on 'path' in CGI::Cookie

  1. path

    If you provide a cookie path attribute, the browser will check it against your script's URL before returning the cookie. For example, if you specify the path "/cgi-bin", then the cookie will be returned to each of the scripts "/cgi-bin/tally.pl", "/cgi-bin/order.pl", and "/cgi-bin/customer_service/complain.pl", but not to the script "/cgi-private/site_admin.pl". By default, the path is set to "/", so that all scripts at your site will receive the cookie.

So I would remove the path for the moment and retry.

As always with perl, if you aren't using strict and warnings then turn them on

于 2013-09-15T20:29:36.877 回答