Mdc::CGI v1.092b - 8:21 PM 2004-11-10
Routines to read CGI input, cookie and client type.
use Mdc::CGI;
my $CGI = new Mdc::CGI;
die "Error: $CGI->{error}" if $CGI->{error};
my $name = $CGI->{query}{name};
$CGI->Print( "Hello $name!" );
Create a new cgi object. Only one object is allowed to be created at a time. You may undef the first object before creating another, but why would you want to to that? Parameters may be supplied during object creation. These parameters are described below.
my $CGI = new Mdc::CGI( EXPIRES => '10D' ); # cookie will expire in 10 days
If the cookie_expires parameter is not defined or is blank, the cookie header will not be given an expiration time which has the effect of being a ``session cookie'', meaning it will expire only after the client browser has been closed.
my $CGI = new Mdc::CGI( CONTEXT => 'path' );
The CONTEXT paramter adjusts the PATH and DOMAIN values of the cookie header. Using this paramter allows you to expose the client cookie to other scripts on your site or even to other sites within your domain. The default is 'script' which will only allow the script which issued the cookie to read it again.
Valid context values: script Only current script will be able to retrieve cookies from client path Expose client cookie to other scripts in same path site Expose client cookie to other scripts and paths in same web site domain Expose client cookie to other scripts within the current domain
At the time of object creation, several parsing routines will gather all of the available client and server data and place it into separate hashes. If an error occures during any of the parsing routines, an error code will be assigned to the object's 'error' attribute.
These routines are described below:
- non-ascii characters - html and meta characters - content length - key size - value size - multiple keys - invalid keys
Examples:
print $CGI->{query}{key}; # directly access a query value
# - or -
my $q = $CGI->{query}; # get the hash reference and...
print $q->{key}; # make your code look a little cleaner
Parse client cookie. Data will be assigned to the hash reference that is provided as argument.
my $err = $CGI->_parse_cookie(\%cookie);
Parse the current SCRIPT_URI. If SCRIPT_URI is not supplied by your web server, it will be constructed. Results are placed in the supplied hash reference.
my $err = $CGI->_parse_url( \%url );
Set the outgoing client cookie.
$CLIENT->SetCookie( key => value, ... );
Clear the client cookie. Supply a list of keys to be cleared.
$CGI->ClearCookie( LIST );
Print a scalar or list to the client.
$CGI->Print( "Hello ", "World!" );
If imported at the ``use'' statement, this method may be called directly as a stand-alone subroutine.
Print "Hello ", "World!";
1201 Invalid character(s) encountered in input data 1202 Invalid character(s) encountered in input key 1203 Input key exceeds maximum length 1204 Input value exceeds maximum length 1205 Invalid character(s) encountered in cookie data 1206 Cookie data exceeds maximum length 1207 Invalid method 1208 Content exceeds maximum length 1209 Possible HTML or meta characters found in input data 1210 Possible HTML or meta characters found in referer string 1211 Input key not defined 1212 Input value not defined 1213 Invalid character(s) in HTTP_USER_AGENT 1214 Invalid character(s) in REMOTE_ADDR 1215 Hex character(s) encountered in input data 1216 Only one CGI object may be defined at a time
Mdc::CGI Copyright (c) 2003-04 Mark K Mueller. All rights reserved. http://www.markmueller.com/