20-3 ?用範?一:網??來訪次數

`NϥΨӤpdҨӻpϥ JavaScript iɮŪPؿŪΡC

ڭ̥ݬݭpƾdҡCڭ̦beXӤp`]gйLpƺdҡAǽdҬOQ Application M Session ܼƨӹFpƪ\AѩoܼƳxsbO餤A]oǭpƸƷ|]A}ӬyCӥp`pƺAONpƸxsb@ӭpɮפAíwAШdҡG

Example]fileAccess/pageHitCounter01.asp^G

bWzdҤAunϥΪ̫UsuszvApƾN|[ 1CdҪlXpUG

lɡ]fileAccess/pageHitCounter01.asp^G]ǦϰUYi^
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
FullPath = Server.MapPath("/jang/courses/fintech/quiz")
Set fd = fso.GetFolder(FullPath)
url=Request.ServerVariables("URL")
thisFileName=fso.GetFileName(url)
parentPath=fso.GetParentFolderName(url)
rarFile=fso.GetFileName(parentPath) & ".rar"
rarPath=fso.GetParentFolderName(parentPath) & "/" & rarFile
'Response.Write(rarPath)
rarExist=fso.FileExists(Server.MapPath(rarPath))
'Response.Write(rarExist)
If rarExist Then
%>

<h3><img src="/jang/graphics/dots/redball.gif"> Download this directory in a compressed file:</h3>
<blockquote>
<a href="<%=rarPath%>"><%=rarFile%></a>
</blockquote>
<%End If%>

<%
' Compute no. of files
fileNum=0
for each f in fd.files
	fileNum=fileNum+1
Next
If fileNum>0 Then	' If fileNum=1 ===> Only this file exists
%>
<h3><img src="/jang/graphics/dots/redball.gif"> File listing:</h3>
<table border=1 align=center>
<tr>
<th>File name</th><th>Size (Bytes)</th><th>Last modified</th>
<%
for each f in fd.files
	If f.name<>thisFileName Then
		response.write("<tr align=center>")
		response.write("<td align=left><a target=_blank href=""" & f.name & """>" & f.name & "</a></td>")
		response.write("<td align=right>" & f.size & "</td>")
		response.write("<td>" & f.DateLastModified & "</td>")
		response.write("<tr>")
	End If
next
%>
</table>
<%End If%>

<%
' Compute no. of folders
folderNum=0
For Each f1 in fd.SubFolders
	folderNum=folderNum+1
Next
If folderNum>0 Then
%>
<h3><img src="/jang/graphics/dots/redball.gif"> Directory listing:</h3>
<table border=1 align=center>
<tr>
<th>Folder name</th>
<%
For Each f1 in fd.SubFolders
	response.write("<tr align=center>")
	response.write("<td align=left><a target=_blank href=""" & f1.name & """>" & f1.name & "</a></td>")
Next
%>
</table>
<%
End If
set fso=nothing
set fd=nothing
%>

ѤWz{XiݥXAڭ̥ͤ@ FileObject AAgѦ OpenTextFile kӶ}ҭpɮרæ^ɮ׫ OutAMAg Out ReadLine M WriteLine kӹɮ׶iŪMgJCbϥΦpƺeAڭ̥dzƤ@ӭpɮס]bҬO pageHitCounter.cnt^AHKxspƸơCѩpƸƫxsbɮפA]ä|]A}ӳypƸƪyC

ڭ̤]iHNpƥ\g@ӨơA{X۰ʥhMpɮסAoɭԥunɤJ]tƪɮסANiHƭpƥ\CҦpG

Example]fileAccess/pageHitCounter02.asp^G

bWzdҤAunϥΪ̫UsuszvApƾN|[ 1CdҪlXpUG

lɡ]fileAccess/pageHitCounter02.asp^G]ǦϰUYi^
<%@language=JScript%>
<% title="Hɮ׬Dpƾ" %>
<!--#include file="../head.inc"-->
<hr>

<center>
<!--#include file="counter.inc"-->
zO <font color=green><%=pageHitCounter()%></font> X.I
<%counterFile=Request.ServerVariables("URL") + ".cnt";%>
<p>]pƸxsb <a href="<%=counterFile%>"><%=counterFile%></a>C^
<p>]u<a href="javascript:history.go(0)">sz</a>vHW[pƸơC^
</center>

<hr>
<!--#include file="../foot.inc"-->

pƸƪɮ׫hOb

lɡ]fileAccess/pageHitCounter02.asp.cnt^G]ǦϰUYi^
7677

counter.inc lXpUG

lɡ]fileAccess/counter.inc^G]ǦϰUYi^
<script runat=server language=jscript>
function pageHitCounter(){
	fso = new ActiveXObject("Scripting.FileSystemObject");
	counterFile = Request.ServerVariables("PATH_TRANSLATED") + ".cnt";	// XOɮצbwФڦm
	fid = fso.OpenTextFile(counterFile, 1);			// }ҰŪɮ
	count = fid.ReadLine();					// qɮŪXOƸ
	fid.Close();						// ɮ
	count++;						// W[OƸ
	fid = fso.OpenTextFile(counterFile, 2);			// }ɮרä\gJ
	fid.WriteLine(count);					// gJɮ
	fid.Close();						// ɮ
	return(count);
}
</script>

<script runat=server language=vbscript>
Function pageHitCounter
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
	counterFile=Request.ServerVariables("PATH_TRANSLATED") & ".cnt"	' XOɮצbwФڦm
	'Response.Write(counterFile)
	Set Out= fso.OpenTextFile(counterFile, 1, FALSE, FALSE)	' }ҰŪɮ
	count = Out.ReadLine					' qɮŪXOƸ
	Out.Close						' ɮ
	count= count+1						' W[OƸ
	Set Out= fso.CreateTextFile (counterFile, TRUE, FALSE)	' }ɮרä\gJ
	Out.WriteLine(count)					' gJɮ
	Out.Close						' ɮ
	pageHitCounter=count					' ^Ǹ
End Function
</script>

bWzdҤApɮתWٳOɮצW٦A[W ".cnt"A]unbɤJ count.incAN㦳ӧOpƥ\C~Aɮץ]tӨơAiHOΦb JScript M VBScriptC


JScript {]pPΡGΩAݪ ASP