如何用ASP创建日志文件
时间:2008-03-10 17:27:00
你是否有时想知道什么人访问你的站点,什么时间,IP地址等。下面我就这个问题向大家来阐述一下。这个例子使用文本文件来写入用户的信息创建一个logfile.asp放在每一个asp的页面的顶端<!--#Include File="LogFile.asp"-->
当有人来访问你的站点logfile.asp自动把他的信息写入LogFile.txt,如果相关的URl一样的话则不写入文件
File: LogFile.asp
<%
Dim ValidEntry ' Log variable
' First set that this log is valid
ValidEntry = True
' If Session Variable "LogIn" is not empty
' that mean this person has already been logged
' then set ValidLog to False
If not IsEmpty(Session("LogIn")) then ValidEntry = False
' Here you can add different restriction
' If the refering url is from same site
' don't write to log file
If Left(Request.ServerVariables("HTTP_REFERER"), 17)="http://devasp.com" Then
ValidEntry = False
End if
If Left(Request.ServerVariables("HTTP_REFERER"), 21)="http://www.devasp.com" Then
ValidEntry = False
End If
' Now if ValidEntry is True then enter to log file
If ValidEntry Then
Const ForAppending = 8
Const Create = true
Dim FSO
DIM TS
DIM MyFileName
Dim strLog
MyFileName = Server.MapPath("MyLogFile.txt")
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TS = FSO.OpenTextFile(MyFileName, ForAppending, Create)
' Store all required values in strLog
strLog = "<br><P><B>" & now & "</B> "
strLog = strLog & Request.ServerVariables("REMOTE_ADDR") & " "
strLog = strLog & Request.ServerVariables("HTTP_REFERER") & " "
strLog = strLog & Request.ServerVariables("HTTP_USER_AGENT") & "<BR>"
' Write current information to Log Text File.
TS.write strLog
TS.Writeline ""
' Create a session varialbe to check next time for ValidEntry
Session("LogIn") = "yes"
Set TS = Nothing
Set FSO = Nothing
End If
%>
标签:日志,asp,ip
0
投稿
猜你喜欢
ServerXMLHTTP的超时设置(setTimeouts)参数含义
2009-02-12 12:51:00
MySQL (root@%) does not exist的问题
2011-03-16 15:31:00
IE中伪类:hover的使用及BUG
2007-05-11 17:04:00
网站设计应当让用户选,别让用户想
2008-03-19 12:01:00
从两个方面讲解SQL Server口令的脆弱性
2009-01-08 13:40:00
QCon大会散记
2010-05-03 14:19:00
img标签中alt和title属性的正确使用
2008-01-10 12:59:00
MySQL 数据编码 latin1 转 UTF8
2010-10-14 14:20:00
js正则的几个基本概念
2007-09-30 20:02:00
详解MySQL 数据库优化方法
2010-08-12 14:50:00
ASP页面内VBScript和JScript的交互
2007-09-11 13:49:00
JS语法检查插件 jsLint for Vim
2010-11-15 21:31:00
网页中英文混排行高不等问题
2008-08-26 17:03:00
保存透明gif时出现锯齿解决法
2008-06-26 18:10:00
MySQL的命令行提示符及其表达的意思
2008-03-17 13:34:00
纯ASP结合VML生成完美图-柱图
2010-05-11 16:48:00
ASP中生成文本文件的两种方式
2008-04-30 19:33:00
CSS中写expression可能会在Chrome中有问题
2010-01-29 13:10:00
Dreamweaver4探谜系列(1)
2010-09-05 21:12:00
ASP GetRef 函数指针试探
2011-03-16 11:09:00