##############################################################################
# CCS CGI Toolkit (cgitoolkit.pm) #
# Copyright 1997 John Cokos, The CCS Network #
# Created 05/01/1997 Last Modified 05/16/1997 #
# Script Home Page: http://www.interactive-web.net #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1997 John C. Cokos All Rights Reserved. #
# #
# This file (cgitoolkit.cgi) may be modified so long as #
# this copyright notice and the comments above remain intact. By using this #
# code you agree to indemnify John C. Cokos from any liability that #
# might arise from it's use. #
# #
# Selling the code for this program without prior written consent is #
# expressly forbidden. In other words, please ask first before you try and #
# make money off of my program. #
# #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium. In all cases copyright and header must remain intact.#
##############################################################################
Function Reference
Locking and Unlocking
Function: lock
Usage: &lock(FILEHANDLE);
Example:
open(DAT,">somefile.txt");
lock(DAT);
print DAT "Hello World\n";
close(DAT);
unlock(DAT);
Function: unlock
Usage: &unlock(FILEHANDLE);
Example:
open(DAT,">somefile.txt");
lock(DAT);
print DAT "Hello World\n";
close(DAT);
unlock(DAT);
Parsing Form Variables
Function: parse_form
Usage: &parse_form;
Notes: This will return 3 Associative Arrays:
1. $input{'fieldname'}
This contains the values the user entered in the form
Ex:
&parse_form;
$NAME = $input{'username'}; ## Whatever the user typed in for "username"
2. $Fields{'fieldname'}
This contains the names of the entry fields on the form
Ex:
&parse_form;
## Show what was entered. This uses both the $input and $Fields arrays...
foreach $field_name (@Fields) {
$field_name =~ s/\n//g;
$field_name =~ s/required-//g;
print "<PREgt;\n";
print "<Bgt;$field_name: </Bgt;<Igt;$input{$field_name}</I>\n";
print "</PREgt;\n";
3. $ENCODED{'fieldname'}
This contains the encoded values the user entered in the form
Ex:
&parse_form;
## Give the user a way to re-submit to the CGI without showing a form/button:
## This example is a guestbook. We pass the program the guestbook name and which
## message group to show...This is necessary because the guestbook name may contain some spaces
## or other goofy characters that we'd rather not try an encode ourselves.
print "<A HREF="guestbook.cgi?guestbook=$ENCODED{'guestbook'}&start_from=$next_set_of_records">Next 25 records</A>\n";
Setting and retrieving cookies
These functions are used to retrieve cookies:
Function: split_cookie
Usage: &split_cookie(COOKIE_STRING,COOKIE_TO_GET);
Ex: %datecookie= &split_cookie( $ENV{ 'HTTP_COOKIE' }, 'last_visit' );
Function: Cookie_Date
Usage: $Variable = &Cookie_Date(TIME);
Ex: $expire_date = &Cookie_Date( time + 31536000 , 1 )
## Sets a cookie to expire in 1 year
These are internal functions that you'll never need to call.
Function: split_sub_cookie
Function: join_cookie
In order to use the "split_cookie" function, you must first set a cookie.
Here's the easiest way:
$expire_date = &Cookie_Date( time + 31536000 , 1 )
$time = time;
## When creating the cookie string, separate multiple cookies with a colon (:)
## and use the \~ as the equivalent of "=". This is for the split_cookie function.
## Here, we create 2 cookie values in one cookie: last_visit and iscool
$newcookie= "last_visit\~$time:iscool\~No";
## Note that we send the Set-Cookie header above the Content-Type !!!
print "Set-Cookie: COOKIENAME=$newcookie;expires=$expire_date;path=/\n";
print "Content-Type: text/html\n\n";
## You can see, that by setting these 2 cookie values in one string, we can call the
## split_cookie function to get whichever value we want.
Sending Email
##############################################
# SUB: Send E-mail (Using regular sendmail)
#
# Takes:
# (To, Subject, From, Mail Command, Message)
Reporting Errors
sub ERROR {
Simple Messaging
sub ok_box {
Date Functions
sub Long_Date {
sub Short_Date {
sub US_Date {
Validation: Checking for illegal characters
## This returns "1 or True if the string FAILS ....
## Example: if ( &Not_Alpha($some_text) ) { &ERROR_PAGE; }
Validation: Checking Email Addresses
## This returns "1 or True if the address FAILS ....
## Example: if ( &Not_Valid_Email($some_address) ) { &ERROR_PAGE; }
## Note that the basis of this function is copyright Matthew M. Wright
## we merely changed the return order and the variable names.
Validation: Checking URLS
## This returns "1 or True if the address FAILS ....
## Example: if ( &Not_Valid_URL($some_url) ) { &ERROR_PAGE; }
Validation: Removing HTML from strings
Validation: Check Spelling of a string
## Paramaters: String to check, path to dictionary ( no trailing slash )
## This returns "1 or True if there are spelling errors...
## And always returns $Spelling_Error_Message Global Variable which contains
## informative text about the spelling errors, warnings, and status.
## Example: if ( &Spelling_Errors($text_string,"./data/dictionary") ) { &ERROR("$Spelling_Error_Message"); }
<