Then I tried to retrieve the cookie using a variety of different methods:my $cookie = $cgi->cookie( -name=>'botLogin', -value=>"$username:$trueName:$Hash"); print $cgi->header(-cookie=>[$cookie,$cookie]),$cgi->start_html(-title +=>'Login');
Using Netscape (version 4.77, or IE 5.5 for that matter), I ran the setting code. Sure enough, the browser asked me if I wanted to accept the cookie. The name and value were right. I accepted. Then I tried to retrieve it--no dice. Eventually I discovered that I had to run the setting script twice in a row before I was able to retreive the cookies. What am I doing wrong? Why aren't my cookies taking the first time?#first method..this attempts to just get anything out there and sh +ow it to me print $cgi->h3("First cookie retrieval method..."); my %cookies = parse CGI::Cookie($ENV{COOKIE}); foreach (keys %cookies) { print $cgi->h2("START $_ => $cookies{$_}"); } print $cgi->h3("End first method."); #second method...like the first, doesn't look for a particular coo +kie print $cgi->h3("Second retrieval method..."); %cookies = fetch CGI::Cookie; foreach (keys %cookies) { print $cgi->h3("START $_ => $cookies{$_}"); } print $cgi->h3("End second method"); #this was my original method...tries to get only the cookie that I + set #then parses it's value to retrieve the data I wanted from it if(defined(my $cookieHolder = $cgi->cookie(-name=>'botLogin'))){ print $cgi->h3("Retrieved cookie named botLoginName: $cookieHo +lder"); } else{ print $cgi->h3("No cookie retrieved."); }
In reply to Cookies Not Getting Set First Time by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |