######################################## ###################
# Function: Get the current time
# Parameter: None
# Return Value: return time in the format of yyyymmddhhmmss
######################################## ###################
Sub get_time
{
My ($ sec, $ min, $ hour, $ day, $ month, $ year) = localtime (Time ());
$ Year + = 1900;
$ Month ++;
$ Today = sprintf ("% 04d % 02d % 02d % 02d % 02d % 02d", $ year, $ month, $ day, $ hour, $ min, $ Sec );
Return $ today;
}
######################################## ###################
# Function: Date of the current day
# Parameter: None
# Return Value: returns the current date in the format of yyyymmdd.
######################################## ###################
Sub get_date
{
My ($ sec, $ min, $ hour, $ day, $ month, $ year) = localtime (Time ());
$ Year + = 1900;
$ Month ++;
$ Today = sprintf ("% 04d % 02d % 02d", $ year, $ month, $ Day );
Return $ today;
}
######################################## ##################
# Load a Page Template
Sub template {
My ($ file) = @_;
$ File = $ tpl_dir. $ file;
Return "" If (! -F $ file );
Open (datafile, $ file) or perror ("unable to read template files $ File please contact the system administrator ");
My $ TXT = "";
While (<datafile> ){
$ TXT. = $ _;
}
Close (datafile );
Return $ txt;
}
# Replace the variables in the page template with the specified values
Sub set_var {
My ($ page, $ Param, $ value) = @_;
$ Page = ~ S // $ {$ Param}/$ value/g;
Return $ page;
}
# Remove spaces at the beginning and end of a string
Sub trim
{
My $ string = shift;
$ String = ~ S/^/S + //;
$ String = ~ S // s + $ //;
Return $ string;
}
######## File lock ############
Open cgifile, "> $ fileconfig" or perror ("sorry, the $ fileconfig configuration file cannot be published. Please try again later ");
Flock (cgifile, 2); # file lock
Print cgifile $ page;
Flock (cgifile, 8); # release a file lock
Close cgifile;
######################################## ##########
sub set_cookie_by_key
{< br> my ($ key, $ Val) =@_;
Print "Set-COOKIE: $ key = $ val; domain = $ domain; Path = $ path;/N ";
}< br> sub get_cookie_by_key
{< br> my ($ cookie_key) =@_;
my ($ chip, $ Val, % cookie );
foreach (split (//, $ ENV {'HTTP _ cookies'}) {
S // + // G;
($ chip, $ Val) = Split (/=/, $ _, 2); # splits on the first =.
$ chip = ~ S/% ([A-Fa-f0-9] {2})/Pack ("C", Hex ($1)/Ge;
$ val = ~ S/% ([A-Fa-f0-9] {2})/Pack ("C", Hex ($1)/Ge;
$ cookie {$ chip }. = "/1" If (defined ($ cookie {$ chip}); #/1 is the multiple separator
$ cookie {$ chip }. = $ val;
}< br> my $ temp;
while (My ($ K, $ v) = each % env)
{< br> $ temp. = "$ k = >v v
";
}< br> return $ cookie {$ cookie_key };< BR >}