CGI::Cookie fetch does not find cookie

爷,独闯天下 提交于 2019-12-13 21:06:52

问题


i have a problem with setting and getting cookie data.

When i call following method:

%cookies = CGI::Cookie->fetch;

And print out the hash using Data::Dumper:

print Dumper(%cookies);

My Cookie that was created before with:

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

Does not show up in the output. But it shows up in my browsers cookie list! All values are set and it seems like a normal cookie. But actually it can't be.

Does someone know what i am doing wrong. Is there a strict order for retrieving cookie data?

I also tried it with the method cgi.pm provides, but it didnt work either.

Please help me!


回答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



来源:https://stackoverflow.com/questions/18814124/cgicookie-fetch-does-not-find-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!