<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
IF fs.FileExists(Server.Mappath("count.txt")) Then
'ตรวจสอบว่ามีไฟล์สำหรับเก็บข้อมูลหรือยัง หากมีแล้วจะทำการอ่านและนับข้อมูล counter เพิ่ม
Set read=fs.OpenTextFile(Server.Mappath("count.txt"),1,False)
data=read.ReadAll ' ทำการอ่านข้อมูลจากไฟล์ แล้วเก็บค่าไว้ที่ตัวแปร data
read.close
data=data+1 'ทำการบวกเพิ่มค่า Counter
Set w=fs.OpenTextFile(Server.MapPath("count.txt"),2,False)
'ทำการเก็บค่าข้อมูลใหม่ลงไฟล์โดยใช้โหมดการเขียนทับ (เลข 2)
w.Write data
w.close : Set fs=Nothing
Response.write "ผู้เยี่ยมชมคนที่ : "&data 'แสดงผล
Else
'หากไฟล์ข้อมูลยังไม่มีให้ทำการสร้างไฟล์เก็บข้อมุลขึ้นมา
data=1
Set w=fs.CreateTextFile(Server.MapPath("count.txt"),True)
w.Write data 'และทำการเริ่มต้นค่าของข้อมูลที่ 1
w.close : Set fs=Nothing
Response.write "ผู้เยี่ยมชมคนที่ : "&data 'แสดงผล
End IF
%>
|