################################################################ # 动态页面生成程序 # # 作者:阮俊杰 # # 最后修改日期:2000年5月27日 # ################################################################ #!/usr/bin/perl print "Content-type: text/html\n\n"; ################################################################ # 记数器,记数变量为$hit_num # ################################################################ open(COUNTFILE,"+<../counter/xiaoan_2.dat") || die "can not open the file"; $hit_str = ; $hit_num=eval($hit_str); $next_num=$hit_num+1; $hit_str=sprintf("%08d",$hit_num); seek(COUNTFILE,0,0); print COUNTFILE $next_num; close(COUNTFILE); ################################################################ # 获取主机日期,变量:$host_date(日期),$host_weekday(星期) # ################################################################ @chn_digit = ("一","二","三","四","五","六","七","八","九","十","十一","十二"); ($nsec,$nmin,$nhour,$nday,$nmon,$nyear,$wday,$yday,$isdst) = localtime(time); if ($wday == 0) { $host_weekday="星期日"; } else { $host_weekday="星期".$chn_digit[$wday-1]; } $nyear += 1900; $nmon=$nmon+1; if ($nmon<10) {$monstr="0$nmon";} else {$monstr="$nmon";} if ($nday<10) {$daystr="0$nday";} else {$daystr="$nday";} $host_date ="$nyear年$monstr月$daystr日"; $nmon=$nmon-1; ################################################################ # 获取阴历日期,变量:$chinese_date(日期) # ################################################################ $chinese_date=" "; &chinesedate_calc; ################################################################ # 发送主页,动态地将其中的日期、星期、阴历及点击次数更改为当前值 # # 其中,变量$if_processed控制是否已经处理变毕 # ################################################################ $pre_auoflush=$FORMAT_AUTOFLUSH; $FORMAT_AUTOFLUSH=1; #自动刷新缓存 $if_processed=0; open(HTMLFILE,") { if($if_processed<1) { $htmlline_str=$_; if($htmlline_str=~/8000年00月00日/) { $htmlline_str=~s/8000年00月00日/$host_date/s; } elsif($htmlline_str=~/星期十/) { $htmlline_str=~s/星期十/$host_weekday/s; } elsif($htmlline_str=~/甲戊年十二月二十八/) { $htmlline_str=~s/甲戊年十二月二十八/$chinese_date/s; } elsif($htmlline_str=~/98765432/) { $htmlline_str=~s/98765432/$hit_str/s; $if_processed=1; } print $htmlline_str; } else { print; } } close(HTMLFILE); $FORMAT_AUTOFLUSH=$pre_auoflush; ################################################################ # 开始子程序chinese_date,以获取阴历日期 # # cal_ref data format: # #year,offsetday of year,year name,month days*12,double month # #days,double month order; # ################################################################ sub chinesedate_calc() { my ($i,$record_i,$str,$num,$day_offset,$double_mon_num,$double_mon_days,$if_in_double_month,$days_accu,$tmp_mon,$tmp_day); @cal_ref=("00.02.0535庚辰3030292930292930293030290101", "01.01.2423辛巳3030293030292930293029303005", "02.02.1242壬午3030293029302929302930290101", "03.02.0131癸未3030293030293029293029300101", "04.01.2221甲申2930303029302930293029303003", "05.02.0939乙酉2930293029303029302930290101", "06.01.2928丙戍3029302930293030302930303008", "07.02.1848丁亥2929302929302930303029300101", "08.02.0737戊子3029293029293029303029300101", "09.01.2625己丑3030292930293029302930303006", "10.02.1444庚寅3029302930292930293029300101" ); $record_i=0; while ($record_i<=10) { $str="20".substr($cal_ref[$record_i],0,2); $num=eval($str); if ($nyear == $num) { $str=substr($cal_ref[$record_i],3,2); $num=eval($str); if ($num > $nmon+1) { $record_i--; last; } elsif ($num < $nmon+1) { last; } else { $str=substr($cal_ref[$record_i],6,2); $num=eval($str); if ($num > $nday) { $record_i--; last; } else { last; } } } $record_i++; } if (($record_i<0) || ($record_i>10)) {$str=" ";goto STOP;} $str=substr($cal_ref[$record_i],8,2); $num=eval($str); $day_offset = $yday-$num; $double_mon_num = eval(substr($cal_ref[$record_i],40,2)); $double_mon_days = eval(substr($cal_ref[$record_i],38,2)); $days_accu = 0; $tmp_mon = 0; $tmp_day = 0;$if_in_double_month = 0; for ($i=0;$i<12;$i++) { $str=substr($cal_ref[$record_i],$i*2+14,2); $num=eval($str); if ($days_accu+$num > $day_offset) { $tmp_mon = $i+1; $tmp_day = $day_offset-$days_accu+1; last; } $days_accu+=$num; if ($double_mon_num-2 == $i) { if ($days_accu+$double_mon_days > $day_offset) { $if_in_double_month = 1; $tmp_mon = $i+1; $tmp_day = $day_offset-$days_accu+1; last; } else { $days_accu+=$double_mon_days; } } } if (($tmp_mon<1) || ($tmp_day<1)) {$str=" ";goto STOP;} $str=substr($cal_ref[$record_i],10,4)."年"; if ($if_in_double_month > 0) { $str .= "闰"; } $str .= $chn_digit[$tmp_mon-1]."月"; if ($tmp_day <= 10) { $str .= "初".$chn_digit[$tmp_day-1]; } elsif ($tmp_day < 20) { $str .= "十".$chn_digit[$tmp_day-11]; } elsif ($tmp_day == 20) { $str .= "二十"; } elsif ($tmp_day < 30) { $str .= "廿".$chn_digit[$tmp_day-21]; } elsif ($tmp_day == 30) { $str .= "三十"; } else { $tr=""; } STOP: $chinese_date=$str; } #子程序结束