?? cgi3.htm
字號(hào):
<html><!-- #BeginTemplate "/Templates/index.dwt" --><head><meta http-equiv=Content-Type content="text/html; charset=gb_2312-80"><title>ChinaPerl</title>
<LINK rel=stylesheet href=mystyle.css type=text/css>
</head><body>
<table border=0 cellspacing=0 bgcolor=#80FFFF width=100%>
<tr>
<td align=left rowspan=2 width=150>
<div align="center"><img src=image/perl.gif height=85 width="85"></div>
</td>
<td align=center><img src=image/perl.gif height=85 width="85"></td>
</tr><tr>
<td colspan=2 align=center> </td>
</tr></table>
<table border=0 width=100% height=400 cellspacing=0 cellpadding=0>
<tr>
<td width=20% valign=top bgcolor="#dddddd">
<table border=0 width=100% cellpadding=0><tr><td width=5%></td>
<td width=95%>
<p align=center>Perl 5教程<br>
<a target=_blank href=http://flamephoenix.126.com>by flamephoenix</a><a href="http://perl.yesky.net"><br>
<font color="red">修訂 by RNY<br>
</font></a>2000-08-30</p>
<p align=center><a href="index.htm">目錄</a></p>
<p align=center>第一部分 Perl語(yǔ)言</p>
<p><a href=perl1.htm>第一章 概述</a></p>
<p><a href=perl2.htm>第二章 簡(jiǎn)單變量</a></p>
<p><a href=perl3.htm>第三章 操作符</a></p>
<p><a href=perl4.htm>第四章 列表和數(shù)組變量</a></p>
<p><a href=perl5.htm>第五章 文件讀寫</a></p>
<p><a href=perl6.htm>第六章 模式匹配</a></p>
<p><a href=perl7.htm>第七章 控制結(jié)構(gòu)</a></p>
<p><a href=perl8.htm>第八章 子程序</a></p>
<p><a href=perl9.htm>第九章 關(guān)聯(lián)數(shù)組(哈希表)</a></p>
<p><a href=perl10.htm>第十章 格式化輸出</a></p>
<p><a href=perl11.htm>第十一章 文件系統(tǒng)</a></p>
<p><a href=perl12.htm>第十二章 引用(指針)</a></p>
<p><a href=perl13.htm>第十三章 面向?qū)ο缶幊?lt;/a></p>
<p><a href=perl14.htm>第十四章 包和模塊</a></p>
<p><a href=func.htm>附錄一 函數(shù)集</a></p>
<p align=center>第二部分 Perl的CGI應(yīng)用</p>
<p><a href=cgi1.htm>第一章 cgilib例</a></p>
<p><a href=cgi2.htm>第二章 動(dòng)態(tài)創(chuàng)建圖像</a></p>
<p><a href=cgi3.htm>第三章 計(jì)數(shù)器的編寫方法</a></p>
<p><a href=cgi4.htm>第四章 Web Server設(shè)置</a></p>
第五章、...<br></td></tr></table></td>
<td width=80% valign=top>
<div align="center"></div>
<table border=0 width=100% cellpadding=0>
<tr bgcolor="#00FF80">
<td colspan="2">
<div align="center"> Perl教程 | <a href="perl5manual.zip">下載全文</a>
| <a target=_blank href=http://www.turbolinux.com.cn/cgi-bin/linux/wwwthreads.pl?action=list&Board=perl>Perl論壇</a>
| <a href="http://perl.yesky.net">推薦站點(diǎn)</a> | 關(guān)于我們 </div>
</td>
</tr>
<tr>
<td colspan="2"><!-- #BeginEditable "body" -->
<p align=center>第三章 計(jì)數(shù)器的編寫方法(未定稿)</p>
<p align=center><a target=_blank href=http://flamephoenix.126.com>by
flamephoenix</a></p>
<a href=#1>一、記錄(log)文件</a><br>
<a href=#1.1>1、grep</a><br>
<a href=#1.2>2、page-stats</a><br>
<a href=#1.3>3、wusage</a><br>
<a href=#2>二、創(chuàng)建自己的計(jì)數(shù)器</a><br>
<a href=#2.1>1、使用DBM文件</a><br>
<a href=#2.2>2、文本文件</a><br>
<a href=#2.3>3、文件鎖定</a><br>
<a href=#2.4>4、輸出計(jì)數(shù)結(jié)果</a><br>
<a href=#2.5>5、www Homepage Access Counter</a><br>
<a href=#2.6>6、使用GD圖形庫(kù)</a><br>
<br>
<br>
計(jì)數(shù)器(Access Counter)可以記錄網(wǎng)頁(yè)被訪問(wèn)的次數(shù),在萬(wàn)維網(wǎng)上的使用十分普遍,其編寫方法很多,從簡(jiǎn)單的SSI命令到用CGI程序生成內(nèi)嵌圖像等。計(jì)數(shù)器除了記錄點(diǎn)擊次數(shù)外,還可以記錄訪問(wèn)者的IP、OS、瀏覽器類型等內(nèi)容,使你對(duì)自己網(wǎng)站的訪問(wèn)情況有個(gè)全面的了解,本章主要介紹點(diǎn)擊次數(shù)的統(tǒng)計(jì)和顯示方法。<br>
<br>
<a name=1></a>一、記錄(log)文件<br>
<a name=1.1>1、grep</a><br>
對(duì)于Web服務(wù)器而言,都有記錄文件記錄著詳細(xì)的訪問(wèn)信息,其名稱通常為access_log,下面是一個(gè)例子:<br>
<blockquote>01: dialup-9.austin.io.com - - [02/Oct/1995:20:18:05 -0500]
"GET /phoenix/ HTTP/1.0" 200 2330<br>
02: crossnet.org - - [08/Oct/1995:19:56:45 -0500] "HEAD / HTTP/1.0"
200 0<br>
03: dialup-2.austin.io.com - - [09/Oct/1995:07:54:56 -0500] "GET
/leading-rein/orders HTTP/1.0" 401 -<br>
04: onramp1-9.onr.com - - [10/Oct/1995:11:11:40 -0500] "GET / HTTP/1.0"
200 1529<br>
05: onramp1-9.onr.com - - [10/Oct/1995:11:11:43 -0500] "GET /accn.jpg
HTTP/1.0" 200 20342<br>
06: onramp1-9.onr.com - - [10/Oct/1995:11:11:46 -0500] "GET /home.gif
HTTP/1.0" 200 1331<br>
07: dialup-3.austin.io.com - - [12/Oct/1995:08:04:27 -0500] "GET
/cgi-bin/env.cgi?<br>
08: SavedName=+&First+Name=Eric&Last+Name=Herrmann&Street=&City=&State=&<br>
09: zip=&Phone+Number=%28999%29+999-9999+&Email+Address=&<br>
10: simple=+Submit+Registration+ HTTP/1.0" 200 1261<br>
11: dialup-20.austin.io.com - - [14/Oct/1995:16:40:04 -0500] "GET
/leading-rein/index.cgi?unique_id=9658-199.170.89.58-813706781 HTTP/1.0"
200 1109</blockquote>
注;當(dāng)主頁(yè)在srm.conf中被命名為welcome.html、index.cgi、index.shtml等時(shí),對(duì)其的訪問(wèn)記錄,可能只含有目錄名而不包含該文件名。<br>
我們可以用UNIX命令grep來(lái)統(tǒng)計(jì)主頁(yè)被訪問(wèn)的次數(shù),grep命令通常輸出每一行匹配結(jié)果,但可以加上參數(shù)-c以輸出匹配行的數(shù)目,grep詳見UNIX幫助。下面是一個(gè)簡(jiǎn)單的例子grep.cgi:<br>
<blockquote>1: #!/usr/local/bin/perl<br>
2: print "content-type: text/html\n\n";<br>
3: $num = `grep -c 'GET / HTTP' /your-server-root/logs/access_log`
;<br>
4: $num += `grep -c 'GET /index.shtml' /your-server-root/logs/access_log`
;<br>
5: $num += `grep -c 'GET /index.html' /your-server-root /logs/access_log`
;<br>
6: print "$num\n";</blockquote>
現(xiàn)在就可以在主頁(yè)中加上SSI指令來(lái)顯示計(jì)數(shù)了,例如:<br>
<blockquote>01: <html><br>
02: <head><title>grep test</title><br>
03: <body><br>
04: <hr noshade><br>
05: This page has been accessed<br>
06: <!--#exec cgi="grep1.cgi" --> times.<br>
07: <hr noshade><br>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -