帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
如何用ASP创建日志文件
作者: 发布时间:2005-03-12 来源:
你是否有时想知道什么人访问你的站点,什么时间,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
%> 
  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·ADO存取数据库如何与HTML结合  (2005-03-12)
 ·如何存取三层式结构的数据库的记  (2005-03-12)
 ·ADO如何新增修改删除数据库的记录  (2005-03-12)
 ·ADO如何锁定RecordSet的记录呢?  (2005-03-12)
 ·如何编程实现修改数据库 login I  (2005-03-12)
 ·如何编程实现备份数据库  (2005-03-12)
 ·如何利用ASP实现邮箱访问  (2005-03-12)
 ·如何 编程实现 备份数据库  (2005-03-12)
 ·Select INTO 语句出错,如何解决  (2005-03-12)
 ·如何在sql server系统表中获得用  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统