?? perl源碼:一種圖形顯示式計數器cgi程序范例.txt
字號:
Perl源碼:一種圖形顯示式計數器CGI程序范例
--------------------------------------------------------------------------------
第八軍團 時間:2004-1-23 15:51:36
<table border="1" bgcolor="#F5DE38" width="81">
<tr>
<td width="75"><img src="http://gzcatv.huyt.net/cgi-bin/counter.cgi?position=5" width="15"
height="17"><img src="http://gzcatv.huyt.net/cgi-bin/counter.cgi?position=4" width="15"
height="17"><img src="http://gzcatv.huyt.net/cgi-bin/counter.cgi?position=3" width="15"
height="17"><img src="http://gzcatv.huyt.net/cgi-bin/counter.cgi?position=2" width="15"
height="17"><img src="http://gzcatv.huyt.net/cgi-bin/counter.cgi?position=1" width="15"
height="17"></td>
</tr>
</table>
上面一段代碼是用作調用此程序的HTML代碼。在要顯示計數的地方放上此段代碼即可。
###########################################################
#!/usr/bin/perl
$counterfile = "counter/counter.txt"; #counter.txt(計數器的數據庫文件)的相對路徑
$imagefile{'0'}="counter/0.gif"; # 0.gif(數字圖片文件)的相對路徑
$imagefile{'1'}="counter/1.gif";
$imagefile{'2'}="counter/2.gif";
$imagefile{'3'}="counter/3.gif";
$imagefile{'4'}="counter/4.gif";
$imagefile{'5'}="counter/5.gif";
$imagefile{'6'}="counter/6.gif";
$imagefile{'7'}="counter/7.gif";
$imagefile{'8'}="counter/8.gif";
$imagefile{'9'}="counter/9.gif";
######################
$|=1;
@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach $query (@querys) {
($name, $value) = split(/=/, $query);
$FORM{$name} = $value;}
$position="$FORM{'position'}";
#上面程序段為接收瀏覽器送來的數據處理段
######################
open(NUMBER,"$counterfile");#用只讀方式打開記錄庫文件
$number=<NUMBER>;#將庫文件內的數據賦給變量$number
close(NUMBER);#關閉數據庫
$number++;#記錄數加一
if ($position==1) {#如果$position(瀏覽器端送來的數據)等于一,則將新數據寫如數據庫
open(NUMBER,">$counterfile");
print NUMBER "$number";
close(NUMBER);}
if (($position>0) && ($position<=length($number))) {#如果$position大于0并且小于$number的字段位數(length($number)是截取$number的字段位數的語句)
$positionnumber=substr($number,(length($number)-$position),1);#截取從$number的右邊開始的第length($number)-$position)}后的一個字符。
else {#否則$positionnumber=0
$positionnumber="0";}
if ($imagefile{$positionnumber}) {#如果$imagefile{$positionnumber}已定義
$imagereturn=$imagefile{$positionnumber};}#則有$imagereturn=$imagefile{$positionnumber}
else {#否則$imagereturn=$imagefile{'0'}
$imagereturn=$imagefile{'0'};}
print "Content-type: image/gif\n\n";設定輸出格式為GIF圖形格式
open(IMAGE,"<$imagereturn");
print <IMAGE>;#顯示$imagereturn內容的圖片文件。
close(IMAGE);
exit 0;#程序結束
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -