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;
Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)
| Views for this page | ||||
|---|---|---|---|---|
| Today | This Week | This Month | This Year | Overall |
| 1 | 1 | 18 | 401 | 525 |
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.
Add your comments