dopel has asked for the wisdom of the Perl Monks concerning the following question:

I am having a problem with retrieving a cookie. I set the cookie then try and get the value back and for some reason the $ENV{HTTP_COOKIE} is not being set. The cookie, however, is being sent. When I run it from the browser I get the cookie notice with the correct content. The %cookie_values variable I try to fetch to just remains empty. I am using the following code.
$permissions = new $cgi->cookie(-name=>'test', -value=>[%info], -expires=>'+1D'); print header(-cookie=>$permissions); %cookie_values = fetch CGI::Cookie; $val = $cookie_values{'test'}->value; print $cgi->start_html( -title=>'Admin Script', -bgcolor=>'blue', );

Replies are listed 'Best First'.
Re: cookie help
by antirice (Priest) on Aug 04, 2003 at 05:31 UTC

    Try a lowercase d.

    
    $permissions = $cgi->cookie(-name=>'test', 
                        -value=>[%info], 
                        -expires=>'+1d');
    

    P.S. path='/' is the default for the cookies CGI.pm creates if no path is set.

    Proof of concept:

    #!/usr/bin/perl -wl use CGI qw(cookie); print "+1d: ",cookie(-name=>'test',-value=>'a',-expires=>'+1d'); print "+1D: ",cookie(-name=>'test',-value=>'a',-expires=>'+1D'); __DATA__ outputs: +1d: test=a; path=/; expires=Tue, 05-Aug-2003 06:15:38 GMT +1D: test=a; path=/; expires=Mon, 04-Aug-2003 06:15:39 GMT

    For the record, it was Mon, 04-Aug-2003 06:15:38 GMT when I ran that.

    Hope this helps.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

Re: cookie help
by edoc (Chaplain) on Aug 04, 2003 at 04:27 UTC

    I believe that some/all versions of IE will not save a cookie if the path is not specified in the cookie.

    $permissions = new $cgi->cookie(-name=>'test', -value=>[%info], -path=>'/', -expires=>'+1D');

    cheers,

    J