|
|
Question : cgi cookie with multiple names / values
|
|
I create a cookie and read it and print it's value something like this.
use CGI::Cookie
my $salt_key=&gensalt($salt_length); my $sess_key = unix_md5_crypt(rand(11),$salt_key);
my $c = new CGI::Cookie(-name => 'sess', -value => $sess_key, -domain => $cook_domain, -path => $cook_path, -secure => 0 );
print "Set-Cookie: $c\n";
%cookies = fetch CGI::Cookie; print $cookies{'sess'};
I would like to know the best method to include other values in the same cookie like
user=bob key=1
Once the additional values are in the cookie are the read and printed the same way or is 1 fetch all I need?
print $cookies{'user'}; print $cookies{'key'};
is it better to make a second cookie or is all data in one cookie acceptable?
|
Answer : cgi cookie with multiple names / values
|
|
You can either create multiple cookies, or one cookie with multiple values. Either way will work. To create one cookie with multiple values:
my $c = new CGI::Cookie(-name => 'sess', -value => [$sess_key, "Value2", "Value3", "Value4"], -domain => $cook_domain, -path => $cook_path, -secure => 0 );
Then to retrieve the values: @values=$cookies{'sess'};
Based on the name of your cookies, it looks like you are creating sessions. If so, you might want to look at the CGI::Session module: http://search.cpan.org/~markstos/CGI-Session-4.20/lib/CGI/Session.pm
|
|
|
|
|