#!/usr/local/bin/perl use CGI; # Some constants to use in our form. @colors=qw/gray coral bisque beige gold green lime linen orchid seashell sienna silver wheat/; @sizes=("",1..7); # Read in the CGI parameters $q = new CGI; # recover the "preferences" cookie. %preferences = $q->cookie('preferences'); # If the user wants to change the background color or her # name, they will appear among our CGI parameters. $preferences{'color'} = $q->param('color') if $q->param('color'); $preferences{'name'} = $q->param('name') if $q->param('name'); $preferences{'size'} = $q->param('size') if $q->param('size'); # Choose the default 'silver' color if not otherwise specified: $preferences{'color'} = 'silver' unless $preferences{'color'}; # Refresh the cookie so that it doesn't expire. This also # makes any changes the user made permanent. $the_cookie = $q->cookie(-name=>'preferences', -value=>\%preferences, -expires=>'+30d'); print $q->header(-cookie=>$the_cookie); # Adjust the title to incorporate the user's name, if provided. $title = $preferences{'name'} ? "Welcome back, $preferences{name}!" : "Customizable Page"; # Create the HTML page. We use several of Netscape's # extended tags to control the background color and the # font size. It's safe to use Netscape features here because # cookies don't work anywhere else anyway. print $q->start_html(-title=>$title, -bgcolor=>$preferences{'color'}); print "\n" if $preferences{'size'} > 0; print <$title You can change the appearance of this page by submitting the fill-out form below. If you return to this page any time within 30 days, your preferences will be restored. END ; # Create the form print join("\n", "
", $q->start_form, "Your first name: ", $q->textfield(-name=>'name', -default=>$preferences{'name'}, -size=>30),"
", "Preferred page color: ", $q->popup_menu(-name=>'color', -values=>\@colors, -default=>$preferences{'color'}), "Font size: ", $q->popup_menu(-name=>'size', -values=>\@sizes, -default=>$preferences{'size'}),"
", $q->submit(-label=>'Set preferences'), "
"); print <The Capricorn Organization Home Page END ;