in reply to CGI::cookie query

Another way that isn't mentioned already: You can only send the CGI header *once*, so that call to header() will be weird. But all you need to do is create an array of cookies and then call header once after the loop; eg replace that last line of the loop with push @cookies, $cookie;, then call print $query->header(-cookie=>@cookies); (note: untested, may have to use a reference to @cookies).

But as other have send, there's a practical limit to cookies. It's better to only send one piece of data across and use a server at your end to extract all the data that you are trying to send now. So you'd create a unique key, write to some database all the info you're trying to save, then send off the cookie with just that key value. Upon getting back that key value by a cookie, it's a lot easier to get that data.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: CGI::cookie query
by costas (Scribe) on Apr 02, 2001 at 20:58 UTC
    THis seems like the best idea!!! I have tried it however with no success. What did you actually mean by 'may have to use a reference to @cookies' Does anybody know if it is possible to writea cookie with an array $query->header(-cookie=>@cookies);
      Use $query->header( -cookie=> \@cookies ); (note the '\', that makes the call use a reference to @cookies as opposed to the variable @cookies itself), instead of what I had initially. Again, it's untested, so it might not work, though I doubt that it won't work this way.
      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
        Strange, it still only prints out the last instance. Can you think of anything else, Im pulling my hair out on this end!! THanks
        Just to show you the code. $inputs is a hash
        sub set_cookie_value { my ($inputs) = @_; $query = new CGI(); my $cookie = ""; my @cookies = (); my $key; foreach $key (keys %$inputs) { $cookie = new CGI::Cookie(-name=>$key, -value=>$inputs->{$key} +, -expires=>$inputs->{$key}, -path=>'/', -domain=>'', -secure=>0); push (@cookies, $cookie); } print $query->header( -cookie=> \@cookies ); }