°¨»çÇÕ´Ï´Ù =_= ¼³Ä¡´Â ¹«»çÈ÷ ³¡³ °Í °°Àºµ¥¿ä
http://hedwig.byus.net/ º¸½Ã¸é
Ä«¿îÅÍ°¡ 1À̽ÃÀÛÀä..
cgiÆÄÀÏÀ» ¤·¤Ã¶»°Ô °íÃÄ¾ß Ä«¿îÅͽÃÀÛ¼ö¸¦ °íÄ¥¼öÀÖÀ»±î¿ä?
´ÙÀ½Àº Ä«¿îÅÍÆÄÀÏÀ» ¸Þ¸ðÀå¿¡¼ ¿¬ °á°úÀÔ´Ï´Ù.
$your_c = &get_cookie($cookiename) + 1;
#####¿À´Ã°ú ¾îÁ¦ÀÇ ¿¬¿ùÀÏ Ãëµæ
$ENV{'TZ'} = 'JST-9';
( $sec, $min, $hour, $day, $mon, $year ) = localtime(time);
($sec2, $min2, $hour2, $day2, $mon2, $year2 ) = localtime(time-24*60*60);
$mon++;
$year += 1900;
$today = "$year-$mon-$day\n";
$mon2++;
$year2 += 1900;
$yesterday = "$year2-$mon2-$day2\n";
#####¿¬¿ùÀÏ ºñ±³
if ($today ne $lastday) {
if ($yesterday ne $lastday) {
$yesterday_c = 0;
} else {
$yesterday_c = $today_c;
}
$today_c = 1;
$lastday = $today;
}
#####6ÀÚ¸®¼ö º¯È¯
$total_c = sprintf("%06d", $total_c);
$today_c = sprintf("%06d", $today_c);
$yesterday_c = sprintf("%06d", $yesterday_c);
$your_c = sprintf("%06d", $your_c);
seek(CNT, 0, 0);
print CNT "$total_c,$yesterday_c,$today_c,$lastday\n";
&unlock_close(CNT);
#####HTTPÇì´õ
print "Content-type: text/plain\n";
&set_cookie($cookiename);
print "\n";
print "cgi=$cgi&total=$total_c&yes=$yesterday_c&today=$today_c&you=$your_
c&load=end&";
exit(0);
#####ÆÄÀ϶ô ¿±â
sub lock_open {
local(*FILE, $name) = @_;
if (!open(FILE, $name)) {
print "content-type: text/plain\n\n";
print "$nameÆÄÀÏÀ» ¿ ¼ö ¾ø½À´Ï´Ù.\n";
exit(0);
}
if ($uselock) {
eval("flock(FILE, 2)");
if ($@) {
print "content-type: text/plain\n\n";
print "$@ÀÌ È¯°æ¿¡¼´Â flock Àº »ç¿ëÇÒ
¼ö ¾ø½À´Ï´Ù\$uselock = 0 À¸·Î ÇØÁÖ¼¼¿ä\n";
exit(0);
}
}
seek(FILE, 0, 0);
}
#####ÆÄÀ϶ô ´Ý±â
sub unlock_close {
local(*FILE) = @_;
if ($uselock) {
eval("flock(FILE, 8)");
}
close(FILE);
}
#####===ÄíŰó¸®
===######################################################################
######
#####ÄíÅ°À¯È¿±â°£
sub get_cookie_date {
$ENV{'TZ'} = 'JST-9';
my( $csec, $cmin, $chour, $cday, $cmon, $cyear, $cwday )
= localtime(time + $dday*60*60*24);
my(@month) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
Dec);
my(@week) = qw(Sun Mon Tue Wed Thu Fri Sat);
return sprintf("%s, %d-%s-%04d %02d:%02d:%02d GMT",
$week[$cwday],$cday,$month
[$cmon+1],$cyear+1900,$chour,$cmin,$csec);
}
#####ÄíÅ°ÀÇ Ãâ·Â
sub set_cookie {
local($cookiename2) = @_;
$cookiedate = &get_cookie_date;
print "Set-Cookie: $cookiename=$your_c; expires=$cookiedate;
\n";
}
#####ÄíÅ°ÀÇ Ãëµæ
sub get_cookie {
local($cookiename1) = @_;
@pairs = split(/; /, $ENV{'HTTP_COOKIE'});
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
if ($name eq $cookiename) {
return $value;
}
}
return '';
}
#########################################################################
##########################