>> KYSCORP.COM TUTORIALS >> Perl Tutorials
Date Script
This tutorial will let you learn how to display the date in your page with perl, in fact this will display the date of your server on which you are hosted, for this you must have a full access to your CGI directory and the SSI (stands for Server Side Includes) must be supported by your server.
# Define Variables #
$Display_Week_Day = '1';
$Display_Month = '1';
$Display_Month_Day = '1';
$Display_Year = '1';
$Display_Time = '0';
$Display_Time_Zone = '0';
$Standard_Time_Zone = 'EST';
$Daylight_Time_Zone = 'EDT';
$Display_Link = '0';
# Done #
####################################################
@Week_Days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@Months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
print "Content-type: text/html\n\n";
if ($Display_Link != 0) {
print "<a href=\"http://www.worldwidemart.com/scripts/\">";
}
($Second,$Minute,$Hour,$Month_Day,
$Month,$Year,$Week_Day,$IsDST) = (localtime)[0,1,2,3,4,5,6,8];
if ($IsDST == 1) {
$Time_Zone = $Daylight_Time_Zone;
}
else {
$Time_Zone = $Standard_Time_Zone;
}
if ($Second < 10) {
$Second = "0$Second";
}
if ($Minute < 10) {
$Minute = "0$Minute";
}
if ($Hour < 10) {
$Hour = "0$Hour";
}
if ($Month_Day < 10) {
$Month_Day = "0$Month_Day";
}
$Year += 1900;
if ($Display_Week_Day != 0) {
print "$Week_Days[$Week_Day]";
if ($Display_Month != 0) {
print " ";
}
}
if ($Display_Month_Day != 0) {
print "$Month_Day";
print " ";
if ($Display_Year != 0) {
print "";
}
}
if ($Display_Month != 0) {
print "$Months[$Month] ";
}
if ($Display_Year != 0) {
print "$Year";
if ($Display_Time != 0) {
print " - ";
}
elsif ($Display_Time_Zone != 0) {
print " ";
}
}
if ($Display_Time != 0) {
print "$Hour\:$Minute\:$Second";
if ($Display_Time_Zone != 0) {
print " ";
}
}
if ($Display_Time_Zone != 0) {
print "$Time_Zone";
}
if ($Display_Link != 0) {
print "</a>";
}
exit;
### Done ###Modifications needed:
- Modify the first line of the script [#!/bin/perl] to suit the configuration of your server (ask your host about it).
- Save your file with the extention .cgi otherwise the server won't 'understand' and execute the script.
- Upload the .cgi file to your server with an FTP client and CHMOD it to 755 (or 777 if it won't work).
- Use Server Side includes (SSI) to include the date in the pages of your choice, use the following synthax : <!--#exec cgi="cgi-bin/date.cgi"--> in this case date.cgi is the name of your file and cgi-bin is the directory containing it, if your page and the date.cgi are in the same directory just use this <!--#exec cgi="date.cgi"-->
- Save the pages in which you included the date.cgi via SSI with the extention .shtml to indicate to your server that these pages have a script inside that must be executed.
- That is all folks !
Submitted by : lept || Copyright Notice: Matt Wright