The code is:
my $cookie1 = $query->cookie(-name => 'userid', -value => "$username", -expires =>
'+1D', -secure => 1, -path => '/');
my $cookie2 = $query->cookie(-name => 'verify', -value => 'TRUE', -expires => '+1D',
-secure => 1, -path => '/');
print $query->header(-type => "text/html", -cookie => [$cookie1, $cookie2]),
$query->start_html(-title => "User Verification Successful"),
$query->h1("Authorization Successful, User $username"),
$query->a({-href=>'/cgi-bin/template.cgi'}, 'Go to main page!!'),
my %cookies = $query->cookie(-name => 'userid');
my %cookies2 = $query->cookie(-name => 'verify');
print %cookies;
print %cookies2;
I did use the CGI::Cookie package with the fetch subroutine, but I thought I would try
it using the CGI package. I took this code from the
http://www.perl.com/doc/manual/html/lib/CGI.html#NETSCAPE_COOKIES. The result is that
these hashes are empty.
John Pitchko
Data Services
Saskatchewan Government Insurance
>>> Bob Showalter <[EMAIL PROTECTED]> 07/29/02 09:46am >>>
> -----Original Message-----
> From: John Pitchko [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 29, 2002 9:40 AM
> To: [EMAIL PROTECTED]
> Subject: fetch CGI::Cookie Trouble
>
>
> Hey guys,
>
> I am having trouble when accessing cookies we've created. I
> am using CGI::Cookie in a script to generate the cookie and
> send it to the browser. This seems to work fine, as the
> cookie is then saved and I can see it in my local Cookies
> folder on my computer. However, when using the fetch
> CGI::Cookie command, we get:
>
> Can't call method "value" on an undefined value at
> /appl/webdocs/cgi-bin/verify.cgi line 45.
>
> We are using the exact code from the manpage and have no idea
> why this is happening. Any suggestions?
Help us out by posting the offending code.
I assume you're doing something like this:
# fetch existing cookies
%cookies = fetch CGI::Cookie;
$id = $cookies{'ID'}->value;
If there is no cookie named 'ID', then $cookies{'ID'} would be
undefined, so $cookies{'ID'}->value would be equivalent to
undef->value;
which is obviously a problem. You really need to make sure you
received a cookie named ID first by something like:
%cookies = fetch CGI::Cookie;
$id = defined($cookies{ID}) && $cookies{ID}->value;
I can't say why you aren't getting the cookie. Make sure everything
is spelled correctly.