![]() |
![]() |
Supporting the evolution of a new free world. |
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Perl-CGI
DOCUMENTATION
NAME
Perl-CGI - Perl for the Web
DESCRIPTION
Perl-CGI is an enhancement of Perl that can be imbedded into HTML code. Perl-CGI works similar to the popular PHP language and covers basic functionality for Web applications.
Features:
Perl-CGI uses the "App" namespace for functions and variables which can be used from your scripts. The internal namespace "PerlCGI" should not be changed.
Perl-CGI supports different kinds of Perl compatible CGI adapter like FastCGI, ModPerl and standard CGI. It was tested on Apache Webserver (http://httpd.apache.org) and Microsoft IIS (http://www.iis.net).
The following documentation describes the functionality of Perl-CGI. Visit http://perldoc.perl.org/perlintro.html for an introduction documentation of Perl.
Functions by Category
Control Functions
Variable Handling Functions
HTTP Functions
Date and Time Functions
String Functions
Filesystem Functions
File Upload Functions
Session Functions
ESCAPING FROM HTML
When perl-cgi parses a file, it looks for opening and closing tags, which tell perl-cgi to start and stop interpreting the code between them. Parsing in this manner allows perl-cgi to be embedded in all sorts of documents, as everything outside of a pair of opening and closing tags is ignored by the perl-cgi parser. Most of the time you will see perl-cgi embedded in HTML documents, as in this example.
<p>This is going to be ignored.</p> <?perl print 'While this is going to be parsed.'; ?> <p>This will also be ignored.</p> You can also use more advanced structures:
<?perl if( $expression ) { ?> <strong>This is true.</strong> <? } else { ?> <strong>This is false.</strong> <? } ?> There are four different pairs of opening and closing tags which can be used in perl-cgi. Two of those are <?perl ?> and <script language="perl"> </script>. The other two are short tags and Perl-CGI style tags, and are less portable.
Perl-CGI Opening and Closing Tags
1. <?perl print 'If you want to serve XML documents, do like this'; ?> 2. <script language="perl"> print "Also suitable to server XML or XHTML documents"; </script> 3. <? print 'This is a SGML processing instruction' ?> <?= expression ?> This is a shortcut for "<? print expression ?>" 4. <* print 'Or, you can use Perl-CGI style tags' *> <*= $variable *> This is a shortcut for "<* print $variable *>" MULTILINE COMMENTS
Perl-CGI implements emdedded comments in two ways.
The first is an internal implementation of embedded comments in =# comment #= style. Use the character sequence =# to start a comment. The opposite sequence #= closes the comment.
Second way is a implementation of perl6 like emdedded comments. Supported brakets are { ( [ < .
For better compatibility with perl scripts Perl6 embedded comments are disabled by default.
<?perl =# perl-cgi multi line comment #= print =# comment #= "not commented\n"; #( this is a multi line comment ) my $var = #{ foo bar } 32; ?> PREDEFINED VARIABLES
CONTROL FUNCTIONS
full
log
Example
<?perl # disable printing errors to the screen @erep = App::error_reporting( 0 ); warn "this message will not be print"; # restore previous settings App::error_reporting( @erep ); ?> directive )
Returns the current value of the specified configuration directive.
Example
<?perl if( App::cfg_get( 'file_uploads' ) ) { print "file uploads are enabled\n"; } else { print "file uploads are not available\n"; } ?> A description of directives can be found her.
Returns the name of the gateway where Perl-CGI runs on it. Possible values are "Console", "CGI", "FastCGI" and "ModPerl".
VARIABLE HANDLING FUNCTIONS
name
$var )
Finds whether the given variable is an array.
$var )
This function is an alias of: is_float().
$var )
Finds whether the type of the given variable is float.
Note: To test if a variable is a number or a numeric string, you must use is_numeric().
$var )
Finds whether the given variable is a hash.
$var )
Finds whether the type of the given variable is integer.
Note: To test if a variable is a number or a numeric string, you must use is_numeric().
$var )
This function is an alias of: is_int().
$var )
This function is an alias of: is_int().
$var )
Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.
$var )
Finds whether the given variable is an object.
$var )
Finds whether the type given variable is string.
$var )
Finds whether the given variable is a unicode string.
$var )
Finds whether the type of the given variable is unsigned integer.
$var )
Returns the type of the Perl variable var.
Return Values
Possibles values for the returned string are:
HTTP FUNCTIONS
replace
$name [, $value [, $expire [, $path
[, $domain [, $secure [, $httponly ]]]]]] )
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction).
Parameters
name
The name of the cookie.
value
expire
path
domain
secure
httponly
Return Values
If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.
$uri )
encode_uri method returns an encoded URI. If you pass the result to decode_uri, the original string is returned. The encode_uri method does encode all characters except the following:
0 to 9
A to Z
a to z
- _ . ! ~ * ' ( )
, / ? : @ & = + $
$uri )
Returns the unencoded version of an encoded Uniform Resource Identifier (URI).
$uri )
encode_uri_component method returns an encoded URI. If you pass the result to decode_uri_component, the original string is returned. The encode_uri_component method does encode all characters except the following:
0 to 9
A to Z
a to z
- _ . ! ~ * ' ( )
$uri )
Returns the unencoded version of an encoded Uniform Resource Identifier (URI).
DATE AND TIME FUNCTIONS
$timestamp] )
Converts a time as returned by the time function to a 9-element list with the time analyzed for the local time zone. Typically used as follows:
<?perl # 0 1 2 3 4 5 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = App::localtime; ?> $format [, $timestamp] )
Format a local time/date according to locale settings
Parameters
format
The following conversion specifiers are recognized in the format string:
%A is replaced by the locale's full weekday name.
%a is replaced by the locale's abbreviated weekday name.
%B is replaced by the locale's full month name.
%b or %h
is replaced by the locale's abbreviated month name.
%C is replaced by the century (a year divided by 100 and
truncated to an integer) as a decimal number [00,99].
%c or %+
is replaced by the locale's appropriate date and time
representation.
%D is replaced by the date in the format ``%m/%d/%y''.
%d is replaced by the day of the month as a decimal number
[01,31].
%e is replaced by the day of month as a decimal number [1,31];
single digits are preceded by a blank.
%F is replaced by the date in the format ``%Y-%m-%d''
(the ISO 8601 date format).
%G is replaced by the ISO 8601 year with century as a decimal
number.
%g is replaced by the ISO 8601 year without century as a
decimal number (00-99). This is the year that includes the
greater part of the week. (Monday as the first day of a
week). See also the '%V' conversion specification.
%H is replaced by the hour (24-hour clock) as a decimal
number [00,23].
%I is replaced by the hour (12-hour clock) as a decimal
number [01,12].
%j is replaced by the day of the year as a decimal number
[001,366].
%k is replaced by the hour (24-hour clock) as a decimal
number [0,23]; single digits are preceded by a blank.
%l is replaced by the hour (12-hour clock) as a decimal
number [1,12]; single digits are preceded by a blank.
%M is replaced by the minute as a decimal number [00,59].
%m is replaced by the month as a decimal number [01,12].
%n is replaced by a newline.
%o or %O
is replaced by the offset from UTC in seconds.
%p is replaced by the locale's equivalent of either
"AM" or "PM".
%P is replaced by the locale's equivalent of either
"AM" or "PM" represented in lower case format.
%R is replaced by the time in the format "%H:%M".
%r is replaced by the locale's representation of 12-hour
clock time using AM/PM notation.
%S is replaced by the second as a decimal number [00,61].
The range of seconds is (00-61) instead of (00-59) to
allow for the periodic occurrence of leap seconds and
double leap seconds.
%s is replaced by the number of seconds since the Epoch,
UTC.
%T is replaced by the time in the format ``%H:%M:%S''.
%t is replaced by a tab.
%U is replaced by the week number of the year (Sunday as the
first day of the week) as a decimal number [00,53].
%u is replaced by the weekday (Monday as the first day of
the week) as a decimal number [1,7].
%V is replaced by the week number of the year (Monday as the
first day of the week) as a decimal number [01,53].
According to ISO 8601 the week containing January 1 is
week 1 if it has four or more days in the new year,
otherwise it is week 53 of the previous year, and the next
week is week 1. The year is given by the `%G' conversion
specification.
%v is replaced by the date in the format "%e-%b-%Y".
%W is replaced by the week number of the year (Monday as the
first day of the week) as a decimal number [00,53].
%w is replaced by the weekday (Sunday as the first day of the
week) as a decimal number [0,6].
%X is replaced by the locale's appropriate time representation.
%x is replaced by the locale's appropriate date representation.
%Y is replaced by the year with century as a decimal number.
%y is replaced by the year without century as a decimal number
[00,99].
%Z is replaced by the time zone name.
%z is replaced by the offset from ITC in the ISO 8601 format
"[-]hhmm".
%% is replaced by '%'.
timestamp
$format [, $timestamp] )
Format a GMT/UTC time/date according to locale settings
Behaves the same as strftime() except that the time returned is
Greenwich Mean Time (GMT). For example, when run in Eastern Standard
Time (GMT -0500), the first line below prints "Dec 31 1998 20:00:00",
while the second prints "Jan 01 1999 01:00:00".
Examples
<?perl App::set_timezone( 'America/New_York' ); $timestamp = App::mktime( 20, 0, 0, 12, 31, 1998 ); print App::strftime( '%b %d %Y %H:%M:%S', $timstamp ) . "\n"; print App::gmstrftime( '%b %d %Y %H:%M:%S', $timestamp ) . "\n"; ?> See Also
strftime()
Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.
Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.
Parameters
hour
The number of the hour.
minute
second
month
day
year
Return Values
mktime() returns the Unix timestamp of the arguments given. If the arguments are invalid, the function returns FALSE.
Examples
mktime() is useful for doing date arithmetic. Convert a SQL datetime to unix timestamp
<?perl $datetime = '1998-12-31 00:00:00'; if( $datetime =~ /(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})/ ) { $timestamp = App::mktime( $4, $5, $6, $2, $1, $3 ); } ?>
Identical to mktime() except the passed parameters represents a GMT date.
gmmktime() internally uses mktime() so only times valid in derived
local time can be used.
Like mktime(), arguments may be left out in order from right to left, with any omitted arguments being set to the current corresponding GMT value.
See Also
mktime()
STRING FUNCTIONS
Return Values
Returns the new locale set, or FALSE if no locale could be found.
$hash_ref )
Set userdefined locale information.
Parameters
hash_ref
A hashref with locale information. Following fields can be set in short or long version:
'dp' or 'decimal_point' => decimal point character
'ts' or 'thousands_sep' => thousands separator
'grp' or 'grouping' => numeric grouping, default is 3
'cs' or 'currency_symbol' => local currency symbol (i.e. $)
'ics' or 'int_curr_symbol' => international currency symbol
(i.e. USD)
'csa' or 'curr_symb_align' => local currency symbol alignment
'l' for left or 'r' for right
'ica' or 'int_curr_symb_align' => international currency symbol
alignment
'l' for left or 'r' for right
'fd' or 'frac_digits' => local fractional digits
'ifd' or 'int_frac_digits' => international fractional digits
'ns' or 'negative_sign' => sign for negative values
'ps' or 'positive_sign' => sign for positive values
'ams' or 'am_string' => A.M. string (i.e. AM)
'pms' or 'pm_string' => P.M. string (i.e. PM)
'sdf' or 'short_date_format' => short date format
(i.e. %m/%d/%Y)
'ldf' or 'long_date_format' => long date format
(i.e. %a %b %d %Y)
'stf' or 'short_time_format' => short time format
(i.e. %H:%M)
'ltf' or 'long_time_format' => long time format
(i.e. %H:%M:%S)
'sdn' or 'short_day_names' => array with short day names
'ldn' or 'long_day_names' => array with long day names
'smn' or 'short_month_names' => array with short month names
'lmn' or 'long_month_names' => array with long month names
Example
<?perl my %locale = ( 'dp' => '.', 'ts' => ',', 'grp' => 3, 'cs' => '$', 'ics' => 'USD', 'csa' => 'l', 'ica' => 'l', 'fd' => 2, 'ifd' => 2, 'ns' => '-', 'ps' => '+', 'ams' => 'am', 'pms' => 'pm', 'sdf' => '%m/%d/%Y', 'ldf' => '%a %b %d %Y', 'stf' => '%H.%M', 'ltf' => '%H.%M.%S', 'sdn' => [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ], 'ldn' => [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ], 'smn' => [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ], 'lmn' => [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], ); App::set_user_locale( \%locale ); print App::strftime( '%c' ), "\n"; ?> $format, $value [, $... ] )
The strfmon() function converts a numeric value to monetary strings according to the specifications in the format parameter. The function converts the double-precision floating-point value parameter under the control of the format parameter and returns the result.
Parameters
format
Contains characters and conversion specifications.
The application shall ensure that a conversion specification consists of the following sequence:
- A '%' character
- Optional flags
- Optional field width
- Optional left precision
- Optional right precision
- A required conversion specifier character that determines the
conversion to be performed
Flags
One or more of the following optional flags can be specified to control the conversion:
=f An '=' followed by a single character f which is used as the
numeric fill character. In order to work with precision or width
counts, the fill character shall be a single byte character; if
not, the behavior is undefined. The default numeric fill
character is the
Field Width
w A decimal digit string w specifying a minimum field width in
bytes in which the result of the conversion is right-justified
(or left-justified if the flag '-' is specified). The default
value is 0.
Left Precision
#n A '#' followed by a decimal digit string n specifying a maximum
number of digits expected to be formatted to the left of the
radix character. This option can be used to keep the formatted
output from multiple calls to the strfmon() function aligned in
the same columns. It can also be used to fill unused positions
with a special character as in "$***123.45". This option causes
an amount to be formatted as if it has the number of digits
specified by n. If more than n digit positions are required,
this conversion specification is ignored. Digit positions in
excess of those actually required are filled with the numeric
fill character (see the =f flag above).
If grouping has not been suppressed with the '^' flag, and it
is defined for the current locale, grouping separators are
inserted before the fill characters (if any) are added. Grouping
separators are not applied to fill characters even if the fill
character is a digit.
To ensure alignment, any characters appearing before or after
the number in the formatted output such as currency or sign
symbols are padded as necessary with
Right Precision
.p A period followed by a decimal digit string p specifying the
number of digits after the radix character. If the value of the
right precision p is 0, no radix character appears. If a right
precision is not included, a default specified by the current
locale is used. The amount being formatted is rounded to the
specified number of digits prior to formatting.
Conversion Specifier Characters
The conversion specifier characters and their meanings are:
i The double argument is formatted according to the locale's
international currency format (for example,
in the U.S.: USD 1,234.56).
n The double argument is formatted according to the locale's
national currency format (for example, in the U.S.: $1,234.56).
% Convert to a '%' ; no argument is converted. The entire
conversion specification shall be %%.
value
Return Values
Returns the converted double-precision floating-point value parameter under the control of the format parameter.
Examples
<?perl print App::strfmon( '%n', 123.45 ), "\n"; ?> Given a locale for the U.S. and the values 123.45, -123.45, and 3456.781, the following output might be produced. Square brackets ( "[]" ) are used in this example to delimit the output.
%n [$123.45] Default formatting
[-$123.45]
[$3,456.78]
%11n [ $123.45] Right align within an 11-character field
[ -$123.45]
[ $3,456.78]
%#5n [ $ 123.45] Aligned columns for values up to 99999
[-$ 123.45]
[ $ 3,456.78]
%=*#5n [ $***123.45] Specify a fill character
[-$***123.45]
[ $*3,456.78]
%=0#5n [ $000123.45] Fill characters do not use grouping
[-$000123.45] even if the fill character is a digit
[ $03,456.78]
%^#5n [ $ 123.45] Disable the grouping separator
[-$ 123.45]
[ $ 3456.78]
%^#5.0n [ $ 123] Round off to whole units
[-$ 123]
[ $ 3457]
%^#5.4n [ $ 123.4500] Increase the precision
[-$ 123.4500]
[ $ 3456.7810]
%(#5n [ $ 123.45 ] Use an alternative pos/neg style
[($ 123.45)]
[ $ 3,456.78 ]
%!(#5n [ 123.45 ] Disable the currency symbol
[( 123.45)]
[ 3,456.78 ]
%-14#5.4n [ $ 123.4500 ] Left-justify the output
[-$ 123.4500 ]
[ $ 3,456.7810 ]
%14#5.4n [ $ 123.4500] Corresponding right-justified output
[ -$ 123.4500]
[ $ 3,456.7810]
$number [, $right_prec [, $dec_point
[, $thou_sep [, $neg_sign [, $pos_sign
[, $left_prec [, $fillchar ]]]]]]] )
Format a number with grouped thousands and other formatings.
Parameters
number
The number to be formated
right_prec
dec_point
thou_sep
neg_sign
pos_sign
left_prec
fillchar
Examples
<?perl $number = 1234.56; # english notation (default locale) print App::number_format( $number ), "\n"; # output: 1,235 # french notation print App::number_format( $number, 2, ',', ' ' ), "\n"; # output: 1 234,56 # financial notation print App::number_format( $number, 2, '.', ',', '-', '+', 7, '0' ), "\n"; # output: +00001,234.56 ?> $subject, $search, $replace )
str_replace() returns a string with all occurrences of search in subject replaced with the given replace value.
This function is about 6 times slower then tr//, but 6 times faster then s//. (perl5.10.0)
<? use Benchmark; $str1 = "AAAAAAAAAAAAAAAAAAAAAAAA"; Benchmark::timethese( 1000000, { 's0_tr//' => \&s0, 's1_s//g' => \&s1, 's2_repl' => \&s2, } ); sub s0 { my $x = $str1; $x =~ tr/A/B/; #print "$x\n"; } sub s1 { my $x = $str1; $x =~ s/A/B/g; #print "$x\n"; } sub s2 { my $x = App::str_replace( $str1, 'A', 'B' ); #print "$x\n"; } ?> Benchmark: timing 1000000 iterations of s0_tr//, s1_s//g, s2_repl... s0_tr//: 1 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 892857.14/s (n=1000000) s1_s//g: 37 wallclock secs (37.49 usr + 0.08 sys = 37.57 CPU) @ 26616.98/s (n=1000000) s2_repl: 7 wallclock secs ( 6.67 usr + 0.00 sys = 6.67 CPU) @ 149925.04/s (n=1000000) Note: This function is case-sensitive. Use str_ireplace() for
case-insensitive replace.
$subject, $search, $replace )
str_ireplace() returns a string with all occurrences of search in subject (ignoring case) replaced with the given replace value.
FILESYSTEM FUNCTIONS
destination
Return Values
Returns TRUE on success or FALSE on failure.
$filename )
Checks whether a file or directory exists.
Return Values
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
$filename [, $textmode] )
file_get() reads the contents of a file into a string.
Parameters
filename
Name of the file to read.
textmode
$filename, $data [, $textmode] )
file_put() writes a string into a file.
Parameters
filename
Path to the file where to write the data.
data
textmode
$filename [, $makehash] )
Gathers the statistics of the file named by filename. If filename is a symbolic link, statistics are from the file itself, not the symlink.
Parameters
filename
Path to the file.
makehash
Return Values
Numeric Name Description
----------------------------------------------------------------
0 dev device number
1 ino inode number
2 mode inode protection mode
3 nlink number of links
4 uid userid of owner
5 gid groupid of owner
6 rdev device type, if inode device *
7 size size in bytes
8 atime time of last access (Unix timestamp)
9 mtime time of last modification (Unix timestamp)
10 ctime time of last inode change (Unix timestamp)
11 blksize blocksize of filesystem IO *
12 blocks number of blocks allocated *
* Only valid on systems supporting it - other systems (e.g. Windows) return -1.
In case of error, file_stat() returns FALSE.
$filename [, $mtime [, $atime]] )
Attempts to set the access and modification times of the file named in the filename parameter to the value given in time.
Parameters
filename
The name of the file being touched.
mtime
atime
Return Values
Returns TRUE on success or FALSE on failure.
Example
<?perl if( App::file_touch( $FileName ) ) { print "$FileName time has been changed to present time\n"; } else { print "Sorry, could not change time of $FileName\n"; } ?> $path )
fullpath() resolves references to '/./', '/../' and extra '/' characters in the input path and returns the canonicalized absolute pathname.
Examples
<?perl # get a lib path relative to the current script $lib_path = App::fullpath( 'lib' ); # returns /path/to/your/script/lib $path = '/var/www/'; print App::fullpath( $path . './../../etc/passwd' ); # will output /etc/passwd ?> $name] )
Creates a temporary file with a unique name in binary read-write (wb+) mode and returns a file handle.
Writes the name of the file in the name parameter if specified.
Return Values
Returns a file handle, similar to the one returned by open(), for the new file, or FALSE on failure.
HANDLING FILE UPLOADS
Perl-CGI is capable of receiving file uploads from any RFC-1867 compliant browser.
A file upload screen can be built by creating a special form which looks something like this:
<!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in %App::FILES hash --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form>
The __URL__ in the above example must point to a Perl-CGI file on the webserver.
The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by Perl-CGI. Fooling this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. The Perl-CGI settings for maximum-size, however, cannot be fooled. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too big and the transfer failed.
The hash %App::FILES will contain all the uploaded file information.
The contents of %App::FILES from the example form is as follows.
Note that this assumes the use of the file upload name userfile, as
used in the example script above. This can be any name.
Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in the config file. The server's default directory can be changed by setting the tmp_dir in the config file.
File Upload Functions
File Upload Error Codes
The given error names are not defined by default.
SESSION HANDLING
Session support in Perl-CGI consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.
A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.
Passing the Session ID
There are two methods to propagate a session id:
The session module supports both methods. Cookies are optimal, but because they are not always available, we also provide an alternative way. The second method embeds the session id directly into URLs.
Alternatively, you can use the constant App::SID which is defined if the session started. If the client did not send an appropriate session cookie, it has the form session_name=session_id. Otherwise, it expands to an empty string. Thus, you can embed it unconditionally into URLs.
Example how to use App::SID
<?perl App::session_start(); $App::SESSION{'count'} ||= 0; $App::SESSION{'count'} ++; ?> <p> Hello visitor, you have called this page for <? print $App::SESSION{'count'} ?> times. </p> <p> To continue, <a href="nextpage.plc?<?= App::SID ?>">click here</a>. </p> Session Handling Functions
Returns TRUE on success or FALSE on failure.
$cache_expire] )
session_cache_expire() returns the current setting of session.cache_expire and sets it to a new value if specified.
The cache expire is reset to the default value of 180 stored in session.cache_limiter at request startup time. Thus, you need to call session_cache_expire() for every request (and before session_start() is called).
$cache_limiter] )
session_cache_limiter() returns the name of the current cache limiter and/or sets it to a new value.
The cache limiter defines which cache control HTTP headers are sent to the client. These headers determine the rules by which the page content may be cached by the client and intermediate proxies. Setting the cache limiter to nocache disallows any client/proxy caching. A value of public permits caching by proxies and the client, whereas private disallows caching by proxies and permits the client to cache the contents.
In private mode, the Expire header sent to the client may cause confusion for some browsers, including Mozilla. You can avoid this problem by using private_no_expire mode. The expire header is never sent to the client in this mode.
The cache limiter is reset to the default value stored in session.cache_limiter at request startup time. Thus, you need to call session_cache_limiter() for every request (and before session_start() is called).
$name] )
session_name() returns the name of the current session and/or sets it to a new value.
The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() is called).
Parameters
name
The session name references the session id in cookies and URLs. It should contain only alphanumeric characters; it should be short and descriptive (i.e. for users with enabled cookie warnings). If name is specified, the name of the current session is changed to its value.
$id] )
session_id() is used to get or set the session id for the current session.
The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() is called).
Parameters
id
If id is specified, it will replace the current session id. session_id() needs to be called before session_start() for that purpose. Depending on the session handler, not all characters are allowed within the session id.
$path] )
session_save_path() returns the path of the current directory used to save session data.
Parameters
path
Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose.
$open, $close, $read, $write, $destroy, $gc
[, $object])
session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by Perl-CGI sessions is preferred. i.e. Storing the session data in a local database.
Example
The following example provides file based session storage similar to the Perl-CGI sessions default save handler.
<?perl App::session_set_handler( 'open', 'close', 'read', 'write', 'destroy', 'gc', MySessionHandler->new() ); App::session_start(); package MySessionHandler; sub new { my $class = shift; my $this = {}; bless $this, $class; return $this; } sub open { my( $this, $save_path, $session_name ) = @_; $this->{'save_path'} = $save_path; return 1; } sub close { my( $this ) = @_; return 1; } sub read { my( $this, $id ) = @_; my $sess_file = $this->{'save_path'} . '/' . $id . '.pcs'; return App::file_get( $sess_file ); } sub write { my( $this, $id, $sess_data ) = @_; my $sess_file = $this->{'save_path'} . '/' . $id . '.pcs'; return App::file_put( $sess_file, $sess_data ); } sub destroy { my( $this, $id ) = @_; my( $sess_file ); $sess_file = $this->{'save_path'} . '/' . $id . '.pcs'; unlink $sess_file; return 1; } sub gc { my( $this, $maxlifetime ) = @_; my( $dh, @files, $file, $now ); $now = time; opendir $dh, $this->{'save_path'} or return 0; @files = grep { /\.pcs$/ } readdir $dh; closedir $dh; foreach( @files ) { $file = $this->{'save_path'} . '/' . $_; if( (stat( $file ))[9] + $maxlifetime < $now ) { unlink $file; } } return 1; } 1; ?>
DESCRIPTION OF CONFIG DIRECTIVES
Print errors to the screen. Enabled by default.
Print errors with filename and line number included. Enabled by default. Disabling it may not work on all errors.
Send errors to STDERR. Enabled by default.
It is disabled on Microsoft IIS, since IIS sends the messages to the browser.
Run a Perl script after starting Perl-CGI.
Set path to temporary files. Defaults to the system temporary directoy.
Set maximum allowed size of data send by POST. Default value is 8M.
Resource Limits
Resource limits are currently working on UNIX systems only.
File Uploads
Sessions
The session management system supports a number of configuration options which you can place in your config file.
RESTRICTIONS
Perl-CGI wertet Zeichenketten mit " oder ' aus, wobei q/ und Verwandte nicht ausgewertet werden. Dadurch können unerwartete Fehler auftreten. Zum Beispiel:
<? $var = q/thali's meat/; ?> # Perl-CGI parses the ' as the begin of a string and ignores the closing # tag ?> which will cause a syntax error # since Perl-CGI breaks strings at the end of line the following works <? $var = q/thali's meat/; ?> AUTHORS
Written by Christian Mueller
COPYRIGHT
PerlCGI is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
SEE ALSO
Project Homepage: http://www.navalla.org/perl-cgi/
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Generated with Perl 5.10.1 and
Perl-CGI 1.0 over
FastCGI within 12.26ms
in memory safe mode.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||