A perl module for creating and parsing forms: http://stein.cshl.org/WWW/software/CGI/. Some of the features that make this wonderfully easy are the ability to test on the command line, easy access to form variables ( param('yourvariable') ), support for cookies, nonparsed headers and more.
Some other nice features include being able to limit the overall amount of script data passed (eliminating some denial of service attacks) and crashing out more gracefully when you or your script screws up. The following code can be exercised at CGI demo. If you give it too much input, it will just throw it away (because of $CGI::POST_MAX). If there's an error (simulated here by checking for the word "foo"), it puts up an error page.
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp 'fatalsToBrowser';
$CGI::POST_MAX=50;
$CGI::DISABLE_UPLOADS = 1; # no uploads
$search=param(search);
#
$foo=param('search');
die "Can't $foo" if $foo =~/foo/;
print header;
print start_html('A Simple Example'),
h2('CGI form'),
start_form,
"Searching for? ",textfield('search'),
p,
"and something else? ",textfield('more'),
p,
submit,
end_form,
hr;
if (param()) {
print
"You wanted: ",em(param('search')),
p,
"and ",em(join(", ",param('more'))),
p,
hr;
} else {
print
"Perhaps you want too much?";
}
print end_html;
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them.
I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar