|
CGI::Lite - Process and decode WWW forms and cookies |
CGI::Lite - Process and decode WWW forms and cookies
use CGI::Lite;
$cgi = new CGI::Lite;
$cgi->set_platform ($platform);
where $platform can be one of (case insensitive):
Unix, Windows, Windows95, DOS, NT, PC, Mac or Macintosh
$cgi->set_file_type ('handle' or 'file');
$cgi->add_timestamp (0, 1 or 2);
where 0 = no timestamp
1 = timestamp all files (default)
2 = timestamp only if file exists
$cgi->filter_filename (\&subroutine);
$size = $cgi->set_buffer_size ($some_buffer_size);
$status = $cgi->set_directory ('/some/dir');
$cgi->set_directory ('/some/dir') || die "Directory doesn't exist.\n";
$cgi->close_all_files;
$cgi->add_mime_type ('application/mac-binhex40');
$status = $cgi->remove_mime_type ('application/mac-binhex40');
@list = $cgi->get_mime_types;
$form = $cgi->parse_form_data;
%form = $cgi->parse_form_data;
or
$form = $cgi->parse_form_data ('GET', 'HEAD' or 'POST');
$cookies = $cgi->parse_cookies;
%cookies = $cgi->parse_cookies;
$status = $cgi->is_error;
$message = $cgi->get_error_message;
$cgi->return_error ('error 1', 'error 2', ...);
$keys = $cgi->get_ordered_keys;
@keys = $cgi->get_ordered_keys;
$cgi->print_data;
$cgi->print_form_data; (deprecated as of v1.8)
$cgi->print_cookie_data; (deprecated as of v1.8)
$new_string = $cgi->wrap_textarea ($string, $length);
@all_values = $cgi->get_multiple_values ($reference);
$cgi->create_variables (\%form);
$cgi->create_variables ($form);
$escaped_string = browser_escape ($string);
$encoded_string = url_encode ($string);
$decoded_string = url_decode ($string);
$status = is_dangerous ($string);
$safe_string = escape_dangerous_chars ($string); # ***use is discouraged***
You can use this module to decode form and query information, including file uploads, as well as cookies in a very simple manner; you need not concern yourself with the actual details behind the decoding process.
Here are the methods you can use to process your forms and cookies:
For multipart/form-data, uploaded files are stored in the user selected directory (see set_directory). If timestamp mode is on (see add_timestamp), the files are named in the following format:
timestamp__filename
where the filename is specified in the ``Content-disposition'' header. NOTE:, the browser URL encodes the name of the file. This module makes no effort to decode the information for security reasons. However, you can do so by creating a subroutine and then using the filter_filename method.
Return Value
Returns either a hash or a reference to the hash, which contains all of the key/value pairs. For fields that contain file information, the value contains either the path to the file, or the filehandle (see the set_file_type method).
$CGI = new CGI::Lite;
while (FCGI::accept > 0)
{
$Query = $CGI->parse_new_form_data();
<process query>
}
Return Value
0 Success
1 Failure
Return Value
The error message.
You can specify either (case insensitive):
Unix EOL: \012 = \n
Windows, Windows95, DOS, NT, PC EOL: \015\012 = \r\n
Mac or Macintosh EOL: \015 = \r
``Unix'' is the default.
This function should be called before you call parse_form_data, or else the directory defaults to ``/tmp''. If the application cannot write to the directory for whatever reason, an error status is returned.
Return Value
0 Failure
1 Success
$cgi->add_mime_type ('application/mac-binhex40');
$cgi->remove_mime_type ('text/html');
Return Value
0 Failure
1 Success
This function should be called before you call parse_form_data, or else it will not work.
$cgi->filter_filename (\&make_uppercase);
$cgi->parse_form_data;
.
.
.
sub make_uppercase
{
my $file = shift;
$file =~ tr/a-z/A-Z/;
return $file;
}
You cannot set a buffer size below 256 bytes and above the total amount of multipart form data. The default value is 1024 bytes.
Return Value
The buffer size.
Return Value
Ordered keys.
Return Value
The modified string.
There was no way I could make this backward compatible with versions older than 1.7. I apologize!
Return Value
Array consisting of the multiple values.
%form = ('name' => 'shishir gundavaram',
'sport' => 'track and field',
'events' => '100m');
If you call this method in the following manner:
$cgi->create_variables (\%hash);
it will create three scalar variables: $name, $sport and $events. Convenient, huh?
&#ascii;
This method does just that.
Return Value
Escaped string.
Return Value
URL encoded string.
Return Value
URL decoded string.
Return Value
0 Safe
1 Dangerous
Return Value
Escaped string.
If you're looking for more comprehensive CGI modules, you can either use the CGI::* modules or CGI.pm. Both are maintained by Dr. Lincoln Stein (lstein@genome.wi.mit.edu) and can be found at your local CPAN mirror and at his Web site:
http://www-genome.wi.mit.edu/WWW/tools/scripting
Maintenance of this module has now been taken over by Smylers <smylers@cpan.org>.
The author thanks the following for finding bugs and offering suggestions:
Copyright (c) 1995, 1996, 1997 by Shishir Gundavaram
All Rights Reserved
Permission to use, copy, and distribute is hereby granted, providing that the above copyright notice and this permission appear in all copies and in supporting documentation.
|
CGI::Lite - Process and decode WWW forms and cookies |