
April 4th, 2008, 09:04 AM
|
|
Contributing User
|
|
Join Date: Mar 2007
Posts: 39
Time spent in forums: 15 h 2 m 10 sec
Reputation Power: 2
|
|
|
Other Language - Cookies in Perl
Can someone show me an example on how to use cookies?
I've been trying to find an easy example online, but I don't understand them.
Here is what I got out of it, but it doesn't work:
Code:
use CGI qw/:standard/;
use CGI::Cookie;
$cookie = new CGI::Cookie(-name => 'filename', -value => 'grades');
$cookie2 = new CGI::Cookie(-name => 'direction', -value => 'Reverse');
print header(-cookie => [$cookie, $cookie2]);
%cookies = fetch CGI::Cookie;
$filename = $cookies{'filename'} -> value;
$direction = $cookies{'direction'} -> value;
print "Set-Cookie: $cookie\n";
I'm assuming that the -name is the name field in the form and the -value is the value field but who knows. So, if I have a form with a text box whose name is filename and value is whatever is put in the textbox and three radio buttons with the name direction and values forward, reverse, and reversebackward. How would I make a cookie so that if the user leaves the page, they will get the same filename they put in the textbox and the same direction radio button they selected when they return to the page?
|