in reply to Empty Cookie

Is your webserver's cgi path really ServerRoot/admin, i.e. you're using "http://www.mydomain.com/admin/script.pl" or "http://www.mydomain.com/admin/subdir/script.pl"as your URL?

Also, it works for me, except that $q->cookie("sessionID") returns a list, not an array reference.

($submitted_user, $submitted_pass) = $q->cookie("sessionID");
Update: here's my working code at http://www.bob-n.com/cgi-bin/test4.pl. Click once to get the cookie sent, reload within 10 seconds to see results of sending it back.

#!/usr/bin/perl -wT use CGI; my $q = CGI->new(); use Data::Dumper; use strict; my ( $submitted_user, $submitted_pass, @rc, @sessionID); @sessionID = qw( PASS USR); if ( @rc = $q->cookie('sessionID') ) { print $q->header(), $q->start_html, $q->pre(['recv cookie', Dumper +(\@rc)]); if ($q->cookie("sessionID")) { ($submitted_user, $submitted_pass) = $q->cookie("sessionID"); print $q->pre([ '$submitted_user, $submitted_pass: ', "$submitted_user, $submitted_pass\n"]); } else { print ("Invalid user/pass. Please login again."); } } else { my $cookie = $q->cookie( -name => 'sessionID', -value => \@sessionID, -expires => '+10s', -path => '/cgi-bin/', -domain => '.bob-n.com', -secure => 0 ); print $q->header(-cookie=>$cookie), $q->start_html; print "<pre>sent cookie:\n", Dumper($cookie), '</pre>'; } print $q->end_html;


--Bob Niederman, http://bob-n.com

Replies are listed 'Best First'.
Re: Re: Empty Cookie
by Anonymous Monk on Jun 27, 2003 at 19:47 UTC

    Thanks for the help. I can't see any problem with the code I've posted, and judging by the fact I can print the cookie but not read it I'd say it has to be either a problem with the version of CGI.pm or with the domain/path settings. I'll try a few things out and post the results if I figure it out.