/usr/share/perl5/CGI/examples
NameSizeModeActions
WORLD_WRITABLE/-0755rm
caution.xbm7410644editdlrm
clickable_image.cgi8080644editdlrm
cookie.cgi22630644editdlrm
crash.cgi1310644editdlrm
customize.cgi24540644editdlrm
diff_upload.cgi15950644editdlrm
file_upload.cgi19980644editdlrm
frameset.cgi20760644editdlrm
index.html34870644editdlrm
internal_links.cgi10190644editdlrm
javascript.cgi30490644editdlrm
make_links.pl1960644editdlrm
monty.cgi20860644editdlrm
multiple_forms.cgi15990644editdlrm
nph-clock.cgi3590644editdlrm
nph-multipart.cgi2630644editdlrm
popup.cgi10240644editdlrm
save_state.cgi23110644editdlrm
tryit.cgi7800644editdlrm
Edit: /usr/share/perl5/CGI/examples/save_state.cgi (2311B)
#!/usr/local/bin/perl use CGI; $query = new CGI; print $query->header; print $query->start_html("Save and Restore Example"); print "

Save and Restore Example

\n"; # Here's where we take action on the previous request &save_parameters($query) if $query->param('action') eq 'SAVE'; $query = &restore_parameters($query) if $query->param('action') eq 'RESTORE'; # Here's where we create the form print $query->start_multipart_form; print "Popup 1: ",$query->popup_menu('popup1',[qw{red green purple magenta orange chartreuse brown}]),"\n"; print "Popup 2: ",$query->popup_menu('popup2',[qw{lion tiger bear zebra potto wildebeest frog emu gazelle}]),"\n"; print "

"; $default_name = $query->remote_addr . '.sav'; print "Save/restore state from file: ",$query->textfield('savefile',$default_name),"\n"; print "

"; print $query->submit('action','SAVE'),$query->submit('action','RESTORE'); print "

",$query->defaults; print $query->endform; # Here we print out a bit at the end print $query->end_html; sub save_parameters { local($query) = @_; local($filename) = &clean_name($query->param('savefile')); if (open(FILE,">$filename")) { $query->save(FILE); close FILE; print "State has been saved to file $filename\n"; print "

If you remember this name you can restore the state later.\n"; } else { print "Error: couldn't write to file $filename: $!\n"; } } sub restore_parameters { local($query) = @_; local($filename) = &clean_name($query->param('savefile')); if (open(FILE,$filename)) { $query = new CGI(FILE); # Throw out the old query, replace it with a new one close FILE; print "State has been restored from file $filename\n"; } else { print "Error: couldn't restore file $filename: $!\n"; } return $query; } # Very important subroutine -- get rid of all the naughty # metacharacters from the file name. If there are, we # complain bitterly and die. sub clean_name { local($name) = @_; unless ($name=~/^[\w\._\-]+$/) { print "$name has naughty characters. Only "; print "alphanumerics are allowed. You can't use absolute names."; die "Attempt to use naughty characters"; } return "WORLD_WRITABLE/$name"; }