The URL of any file located in your cgi-bin is: http://cgi.tripod.com/your_membername/cgi-bin/filename.
require TripodDate;This lets the Perl interpreter know that you want to have access to the functions in the module. Next, you can create an "object" that will let you access those functions (if you know any object-oriented programming, this should sound familiar - otherwise, just think of the object as a simple way to get access to those functions). You do that like this:
$CGI = new TripodDate;The variable $CGI is now a TripodDate object. With it, you can use the functions in the TripodDate module. For example, you can use the currentDate() function, which returns today's date, like this:
$todays_date = $CGI->currentDate();This would assign the date to the $todays_date variable.
$form_address = $CGI->param('address');If you just want to know all of the names of the inputs returned by the form, don't specify an input, and the names of all the inputs will be returned as an array - like this:
@all_inputs = $CGI->param();The other function you might want to use is redirect(). redirect() lets you specify the URL of a page or script that you want to move your visitor to. You could use it like this:
$CGI->redirect('http://www.tripod.com'); <- redirects to the Tripod front page
* currentDate(); * convertMonthNameToInt(); * currentDay(); * convertIntToMonthName(); * currentMonth(); * dateIsPast(); * currentYear(); * addNMonthsToDate(); * massageDate(); * addNDaysToDate(); * convertYearToYYYY(); * isValidDate();The first four functions, currentDate(), currentDay(), currentMonth(), and currentYear(), are very similar. None of them take any arguments, and each returns a single string, like this:
$todays_date = $DATE->currentDate();Note that all of the above functions return their information in mm/dd/yyyy format - so if today is July 16th, 1999, currentDate() would return '08/16/1999', and currentMonth() would return '08'.
$unformatted_date = '9/6/99'; $formatted_date = $DATE->massageDate($unformatted_date);$formatted_date would then be equal to '09/06/1999'. Note that massageDate() can handle dates using dashes or slashes, but the date needs to be numerical, and it needs to be in the standard U.S. ordering of month/day/year.
$two_digit_year = '78'; $four_digit_year = $DATE->convertYearToYYYY();This will make $four_digit_year equal '1978'.
$month_name = 'February'; $month_number = $DATE->convertMonthNameToInt($month_name); $month_name_again = $DATE->convertIntToMonthName($month_number);dateIsPast() checks to see if a given date has already occurred. The date should be in month/day/year format. It returns 1 if the date is past, 0 otherwise. Use it like this:
$date_in_question = '1/1/2000'; if ($DATE->dateIsPast($date_in_question)) { print "Y2K has already occurred.\n"; } else { print "Y2K hasn't happened yet - there's still time to prepare!\n"; }Our last functions are another pair: addNMonthsToDate() and addNDaysToDate(). Both require a date and a number; that number is added to the date to produce a new date. Note that the number can be negative, so you can subtract as well. For example:
$moon_walk_date = '07/20/69'; $five_days_later = $DATE->addNDaysToDate($moon_walk_date, '5'); $ten_months_earlier = $DATE->addNMonthsToDate($moon_walk_date, '-10');
$template_file = 'log_template.txt'; $variable_hash{timezone} = $ENV{TZ}; $variable_hash{ip_address} = $ENV{REMOTE_HOST}; $variable_hash{browser} = $ENV{HTTP_USER_AGENT}; $log_line = $INSERT->fetchInsert($template_file); open (LOG, '>> my_log.txt'); print LOG $log_line; close LOG;The 'log_template.txt' that goes with the script looks like this:
----------------------------- Timezone: $timezone IP: $ip_address Browser: $browser -----------------------------This example works like the example given for sendPage(), except that here each visitor's timezone, ip address, and browser are added to a log file named 'my_log.txt', rather than being outputted as a web page.
To: $email From: FredFlintstone@hotmail.com Subject: YabbaDabbaDoo! Hello $name, Congratulations! You're user number $number of this mail script!You can add other email headers (Reply-To:, Errors-To:, etc), but To: and From: are mandatory. You can customize your email by adding variables wherever you would like to fill something in on the fly. The sendMail method requires 2 parameters- the location of the mail template file, and a reference to a hash of variables. The keys of the varaible hash should correlate with the variables in the mail template.
require TripodMail; $MAIL = new TripodMail; $mail_template = "./flintstones_mail.txt"; %variables = ('email' => 'Wilma@gurlmail.com', 'name' => 'Wilma', 'number' => '2'); $MAIL->sendMail($mail_template, \%variables);Note: In order to prevent spamming, you will be limited to sending out 240 mails per day.
$page_location = 'example.html'; $variable_hash{timezone} = $ENV{TZ}; $variable_hash{ip_address} = $ENV{REMOTE_HOST}; $variable_hash{browser} = $ENV{HTTP_USER_AGENT}; $PAGE->sendPage($page_location, \%variable_hash); exit;The 'example.html' file referred to at the beginning might look something like this:
Together, this script and html file will output a page that shows the viewer's browser, ip address, and timezone. First, the script specifies the name of the html file that we will be using. Second, it creates a hash which contains all the variables contained within the page - in this case, 'timezone', 'ip_address', and 'browser' - and assigns values to each of them. Note that in this case it is getting the values out of a special hash called %ENV, which contains environment variables that all CGI scripts have access to, but you could have different variables that get their values from other places, like random numbers, the time or date, input from a form, etc. Finally, the script calls sendPage() to take the html file and fill in the variables with the contents of the hash. sendPage() looks at the html and searches for words preceded by dollar signs. In our example file, it finds $timezone, $browser, and $ip_address. Each of these then gets replaced by the values from the hash. So the output might look something like this:Example Page Example Page
You are coming in from this timezone: $timezone
You are using the $browser browser. Your ip address is $ip_address.
That's what you'd see if you were using my personal computer at Tripod - you'd see something quite different. This is what's cool about sendPage() - it lets you present different information in your page under different circumstances.Example Page Example Page
You are coming in from this timezone: US/Eastern
You are using the Mozilla/4.61 [en] (Win98; U) browser. Your ip address is 208.7.131.186.
$PAGE->printHeader(); print "A really simple page."; exit;That will output a page which says 'A really simple page.' and nothing else. You might want to use printHeader() instead of sendPage() if you are creating such a dynamic web page that you need write all the HTML from within your script, rather than using an HTML file as a template and filling in variables.