PDA

View Full Version : How to create a simple web tracker in TEXT format?


NinjaTurtle
08-06-2003, 04:43 AM
Dear,

how to generate a simple web tracker without DB & Cookies?
i just need to record down their IP address, Date & Time, Visit time.

glenngv
08-06-2003, 05:16 AM
FileSystemObject (http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject.html)

NinjaTurtle
08-06-2003, 09:23 AM
but what i want is not just simple as that, i want it to be accumulate, eg.

inside the Log.txt:
6/8/2003 10:00:52 200.1.2.7 Jason
6/8/2003 13:45:12 200.184.5 James
.
.
.

everytime a user login that page i will capture his/her name, IP address and log time as well.

raf
08-06-2003, 10:01 AM
All you need to do is build the line you want to write, and replace the "Your text goes here." from this line
filetxt.WriteLine("Your text goes here.")
with it.
Something like

dim linevalue
linevalue = CStr(Now) & " " & Request.ServerVariables("REMOTE_ADDR") & " " & request.form("username")
filetxt.WriteLine(linevalue)


You need to change the text in bold (probably another formfield-name and maybe anothe collection like the querystring or so)

NinjaTurtle
08-06-2003, 10:13 AM
Dear,
i can get the txt file, BUT it will overwrite the single record, i want APPENDING the record to keep as history...

eg:
first login
second login
third login
forth login
.
.
.
.

raf
08-06-2003, 10:28 AM
Maybe post the code you use so we can see what's wrong ...

NinjaTurtle
08-06-2003, 10:40 AM
FileName = Year(now())&month(now())&day(now())
AnalysisName = Server.MapPath(FileName&".txt")

Set fso= CreateObject("Scripting.FileSystemObject")
Set filetxt = fso.CreateTextFile(AnalysisName, True)
path = fso.GetAbsolutePathName(AnalysisName)
getname = fso.GetFileName(path)
set objF = fso.GetFile(AnalysisName)

linevalue = CStr(Now) & " " & Request.ServerVariables("REMOTE_ADDR")
filetxt.WriteLine(linevalue)

filetxt.Close

raf
08-06-2003, 11:00 AM
Well, the first problem i see is that you create a new file for every login.
So it's quite normal you only get one line in the file. If you check the folder, you'll see there is a list of files there.

You only need to create the file once.
When you proces te logins, you only need to open the file (for writing) and write the line. Something like


Dim fso, handler, linevalue
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForWriting = 2
linevalue = CStr(Now) & " " & Request.ServerVariables("REMOTE_ADDR")

Set handler = fso.OpenTextFile("c:\test.txt", ForWriting, True)
handler.WriteLine(linevalue)
handler.Close


You need to replace the fileadres with you own.

NinjaTurtle
08-06-2003, 11:47 AM
Did u meant that i have to generate a file "test.txt" first?

but the Log file is generate everyday if user log in??!!!

Roelf
08-06-2003, 12:49 PM
no, you dont have to create anything first, the True part in:
Set handler = fso.OpenTextFile("c:\test.txt", ForWriting, True)
says: create the file if it doesnt exist, open it if it does exist

if you want to use one file each day, you can enter your own filenamevariable in the opentextmethod

raf
08-06-2003, 12:56 PM
Did u meant that i have to generate a file "test.txt" first?
No. I meant the other way around. Where i have c:\test.txt, there you need to place the name of your textfile. Something like

FileName = Year(now())&month(now())&day(now())
AnalysisName = Server.MapPath(FileName&".txt")
...
Set handler = fso.OpenTextFile(AnalysisName, ForWriting, True)

+
what Roelf said

Roy Sinclair
08-06-2003, 06:13 PM
Pardon me for asking the obvious but why would you want to do this? IIS comes with a built in logging facility which makes it quite easy to track exactly what you are looking for.

whammy
08-06-2003, 08:41 PM
First of all, Roy Sinclair is right.

Secondly, if you had actually looked through everything at the link that GlennGV gave you, you CAN append with FileSystemObject.

So, again, I post links:

http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject.html
http://www.w3schools.com/asp/asp_ref_filesystem.asp

whammy
08-06-2003, 08:42 PM
P.S. You don't want to use forWriting, you want to append, which is 8:

Set handler = fso.OpenTextFile("c:\test.txt", 8, True)

raf
08-06-2003, 09:20 PM
:o My bad. Been a while since i used them. Thanks for setting that straight Whammy :thumbsup:

whammy
08-06-2003, 09:43 PM
No problem. Actually I think FSO is a "must know" for anyone that develops in ASP.

NinjaTurtle
08-11-2003, 04:32 AM
Now i face another problem.
i wanna read all the txt files, extract all the rows of record into a single HTML table format as a report.

It's work if i only read a single file, how if for so many txt files???
i create a txt file by using date(eg: 11/8/2003 the file name should be 2003811.txt).

but inside the particular folder, its contain many txt files, but i just want the certain txt files only. AND can i do sorting b4 the record displayed?!

whammy
08-11-2003, 07:13 AM
Yes, yes, and yes (learn the FileSystemObject and all will become clear to you). :)

Wow, that's a lot of questions! How about we tackle them one or two at a time? Or somebody else go! :D