#!/usr/bin/perl -w #################### # # Cookies demo # ##################### use CGI; use CGI::Carp qw(fatalsToBrowser); # Send "die" messages to browser window my $cgi = new CGI; # One way of using CGI.pm - object oriented. my $cookieName = "Jim's Demo MSIE Cookie"; my $defaultColor = ''; # Try to fetch the user's favorite color either # from (a) form input, or (b) a cookie passed in through the input HTTPD request. my $color = ( $cgi->param( 'color' ) or $cgi->cookie( -name=>$cookieName ) or $defaultColor ); # In any case, create a new cooke, which will be passed back to the # browser as part of the header. my $cookie = $cgi->cookie( -name=>$cookieName, -value=>$color ); # Now output the HTTPD header, and at the same set the new browser cookie. print $cgi->header( -cookie=>$cookie ); # Print the web page, asking for a favorite color. # And if $color is set, report what the color is. print $cgi->start_html( -title => 'What is Your Favorite Color?', -BGCOLOR => 'white', ); print $cgi->start_form(); print "
\n"; print "Favorite Color: \n"; print "