lhp@nereida:~/public_html/cgi-bin/tt$ cat -n ttcgi5.pl 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 use Template; 5 use CGI; 6 7 $| = 1; 8 9 my $cgi = CGI->new(); 10 my $tt = Template->new( 11 WRAPPER => 'page' 12 ); 13 my $input = 'cgicookie.html'; 14 my @cookies; 15 16 my $vars = { 17 cgi => $cgi, 18 cookies => \@cookies, 19 bgcol => 'lightblue', 20 }; 21 22 my $output; 23 24 $tt->process($input, $vars, \$output) 25 || die $tt->error( ); 26 27 if (@cookies) { 28 @cookies = ('-cookie', [ @cookies ]); 29 } 30 31 print $cgi->header(@cookies), $output;
lhp@nereida:~/public_html/cgi-bin/tt$ cat -n cgicookie.html 1 [% IF (cookie = cgi.cookie('SessionID')) %] 2 <h1>Got Cookie</h1> 3 <p> 4 Your SessionID is [% cookie %]. 5 </p> 6 [% ELSE %] 7 [% cookie = cgi.cookie( 8 name = 'SessionID', 9 value = 12345678, 10 expires = '+1m' 11 ); 12 cookies.push(cookie) 13 %] 14 15 <h1>Set Cookie</h1> 16 <p> 17 Cookie has been set. Please reload page. 18 </p> 19 [% END %]
Casiano Rodríguez León