GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
CGI::Utils(3) User Contributed Perl Documentation CGI::Utils(3)

CGI::Utils - Utilities for retrieving information through the Common Gateway Interface

 use CGI::Utils;
 my $utils = CGI::Utils->new;

 my $fields = $utils->vars; # or $utils->Vars
 my $field1 = $$fields{field1};

     or

 my $field1 = $utils->param('field1');


 # File uploads
 my $file_handle = $utils->param('file0'); # or $$fields{file0};
 my $file_name = "$file_handle";

This module can be used almost as a drop-in replacement for CGI.pm for those of you who do not use the HTML generating features of CGI.pm

This module provides an object-oriented interface for retrieving information provided by the Common Gateway Interface, as well as url-encoding and decoding values, and parsing CGI parameters. For example, CGI has a utility for escaping HTML, but no public interface for url-encoding a value or for taking a hash of values and returning a url-encoded query string suitable for passing to a CGI script. This module does that, as well as provide methods for creating a self-referencing url, converting relative urls to absolute, adding CGI parameters to the end of a url, etc. Please see the METHODS section below for more detailed descriptions of functionality provided by this module.

File uploads via the multipart/form-data encoding are supported. The parameter for the field name corresponding to the file is a file handle that, when evaluated in string context, returns the name of the file uploaded. To get the contents of the file, just read from the file handle.

mod_perl is supported if a value for apache_request is passed to new(), or if the apache request object is available via Apache->request, or if running under HTML::Mason. See the documentation for the new() method for details.

If not running in a mod_perl or CGI environment, @ARGV will be searched for key/value pairs in the format

 key1=val1 key2=val2

If all command-line arguments are in this format, the key/value pairs will be available as if they were passed via a CGI or mod_perl interface.

Returns a new CGI::Utils object. Parameters are optional. CGI::Utils supports mod_perl if the Apache request object is passed as $params{apache_request}, or if it is available via Apache->request (or Apache2::RequestUtil->request), or if running under HTML::Mason.

You may also pass max_post_size in %params.

Returns the fully URL-encoded version of the given string. It does not convert space characters to '+' characters.

Aliases: url_encode()

Returns the fully URL-encoded version of the given string as unicode characters. It does not convert space characters to '+' characters.

Aliases: url_unicode_encode()

Returns the decoded version of the given URL-encoded string.

Aliases: url_decode()

Returns the decoded version of the given URL-encoded string, with unicode support.

Aliases: url_unicode_decode()

Takes a hash of name/value pairs and returns a fully URL-encoded query string suitable for passing in a URL. By default, uses the newer separator, a semicolon, as recommended by the W3C. If you pass in a second argument, it is used as the separator between key/value pairs.

Aliases: url_encode_vars()

Takes a URL-encoded query string, decodes it, and returns a reference to a hash of name/value pairs. For multivalued fields, the value is an array of values. If called in array context, it returns a reference to a hash of name/value pairs, and a reference to an array of field names in the order they appear in the query string.

Aliases: url_decode_vars()

Escapes the given text so that it is not interpreted as HTML. &, <, >, and " characters are escaped.

Aliases: escape_html()

Escapes the given text so that it is valid to put in a form field.

Aliases: escape_html_form_value()

Returns a url referencing top level directory in the current domain, e.g., http://mydomain.com

Aliases: get_self_ref_host_url()

Returns a url referencing the current script (without any query string).

Aliases: get_self_ref_url

Returns the current URI.

Aliases: get_self_ref_uri()

Returns a url referencing the current script along with any query string parameters passed via a GET method.

Aliases: get_self_ref_url_with_query()

Returns a url reference the current script along with the given hash of parameters added onto the end of url as a query string.

If the optional $sep parameter is passed, it is used as the parameter separator instead of ';', unless the URL already contains '&' chars, in which case it will use '&' for the separator.

Aliases: get_self_ref_url_with_params()

Returns a url referencing the directory part of the current url.

Aliases: get_self_ref_url_dir()

Converts a relative URL to an absolute one based on the current URL, then adds the parameters in the given hash $params as a query string.

If the optional $sep parameter is passed, it is used as the parameter separator instead of ';', unless the URL already contains '&' chars, in which case it will use '&' for the separator.

Aliases: convertRelativeUrlWithArgs(), convert_relative_url_with_params(), convert_relative_url_with_args()

Takes a url and reference to a hash of parameters to be added onto the url as a query string and returns a url with those parameters. It checks whether or not the url already contains a query string and modifies it accordingly. If you want to add a multivalued parameter, pass it as a reference to an array containing all the values.

If the optional $sep parameter is passed, it is used as the parameter separator instead of ';', unless the URL already contains '&' chars, in which case it will use '&' for the separator.

Aliases: add_params_to_url()

Parses the cookies passed to the server. Returns a hash of key/value pairs representing the cookie names and values.

Aliases: get_parsed_cookies

Returns the CGI parameter with name $name. If called in array context, it returns an array. In scalar context, it returns an array reference for multivalued fields, and a scalar for single-valued fields.

Also Vars() to be compatible with CGI.pm. Returns a reference to a tied hash containing key/value pairs corresponding to each CGI parameter. For multivalued fields, the value is an array ref, with each element being one of the values. If you pass in a value for the delimiter, multivalued fields will be returned as a string of values delimited by the delimiter you passed in.

Aliases: vars(), Vars(), get_args(), args()

# Other information provided by the CGI environment

Returns additional virtual path information from the URL (if any) after your script.

Returns the dotted decimal representation of the remote client's IP address.

Returns the name of the remote host, or its IP address if the name is unavailable.

Returns the name of the host in the URL being accessed. This is sent as the Host header by the web browser.

Returns the referring URL.

Returns the protocol, i.e., http or https.

Returns the request method, i.e., GET, POST, HEAD, or PUT.

 Returns the content type.

Returns the physical path information if provided in the CGI environment.

Returns a query string created from the current parameters.

Generates HTTP headers. Standard arguments are content_type, cookie, target, expires, and charset. These should be passed as name/value pairs. If only one argument is passed, it is assumed to be the 'content_type' argument. If no values are passed, the content type is assumed to be 'text/html'. The charset defaults to ISO-8859-1. A hash reference can also be passed. E.g.,

 print $cgi_obj->getHeader({ content_type => 'text/html', expires => '+3d' });

The names 'content-type', and 'type' are aliases for 'content_type'. The arguments may also be passed CGI.pm style with a '-' in front, e.g.

 print $cgi_obj->getHeader( -content_type => 'text/html', -expires => '+3d' );

Cookies may be passed with the 'cookies' key either as a string, a hash ref, or as a CGI::Cookies object, e.g.

 my $cookie = { name => 'my_cookie', value => 'cookie_val' };
 print $cgi_obj->getHeader(cookies => $cookie);

You may also pass an array of cookies, e.g.,

 print $cgi_obj->getHeader(cookies => [ $cookie1, $cookie2 ]);

Aliases: header(), get_header

Like getHeader() above, except sends it. Under mod_perl, this sends the header(s) via the Apache request object. In a CGI environment, this prints the header(s) to STDOUT.

Aliases: send_header()

Returns the header required to do a redirect. This method also accepts named arguments, e.g.,

 print $cgi_obj->getRedirect(url => $url, status => 302,
                             cookie => \%cookie_params);

You may also pass a cookies argument as in getHeader().

Aliases: redirect()

Like getRedirect(), but in a CGI environment the output is sent to STDOUT, and in a mod_perl environment, the appropriate headers are set. The return value is 1 for a CGI environment when successful, and Apache::Constants::REDIRECT in a mod_perl environment, so you can do something like

 return $utils->sendRedirect($url)

n a mod_perl handler.

Aliases: send_redirect()

Like getRedirect(), except that the redirect URL is converted from relative to absolute, including the host.
Returns a string to pass as the value of a 'Set-Cookie' header.

Returns a string to pass as the 'Set-Cookie' header(s), including the line ending(s). Also accepts a simple hash with key/value pairs.

Sets the cookie generated by getCookieString. That is, in a mod_perl environment, it adds an outgoing header to set the cookie. In a CGI environment, it prints the value of getSetCookieString to STDOUT (including the end-of-line sequence).

Returns a reference to a hash containing the header information sent along with a file upload.

Shortcut methods are provided for returning Apache constants under mod_perl. The methods figure out if they are running under mod_perl 1 or 2 and make the appropriate call to get the right constant back, e.g., Apache::Constants::OK() versus Apache::OK(). The methods are created on the fly using AUTOLOAD. The method names are in the format apache_$name where $name is the lowercased constant name, e.g., $utils->apache_ok, $utils->apache_forbidden. See <http://perl.apache.org/docs/1.0/api/Apache/Constants.html> for a list of constants available.

You can export methods into your namespace in the usual way. All of the util methods are available for export, e.g., getSelfRefUrl(), addParamsToUrl(), etc. Beware, however, that these methods expect to be called as methods. You can also use the tag :all_utils to import all of the util methods into your namespace. This allows for incorporating these methods into your class without having to inherit from CGI::Utils.

Other people who have contributed ideas and/or code for this module:

    Kevin Wilson

Don Owens <don@regexguy.com>

Copyright (c) 2003-2008 Don Owens

All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

0.12
2008-11-13 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.