(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
Printer Friendly Version

2005/01/25 CGI.pm

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.


Hate these ads?



#!/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;







Comments /Words/2005_01_25.html


Add your comments

LOD Communications, Inc.

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
1118401 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.

Publishing your articles here

pavatar.jpg
More:
       - Perl
       - Security




Unix/Linux Consultants

Your ad here - $24.00 yearly!

larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting


http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses


http://www.m3ipinc.com Security, firewalls, ids, audits, vulnerability assesments, BS7799, HIPAA, GLB, incident handling







Coming Attractions

My Favorites

Change Congress


Related Posts