设为首页
加入收藏
联系站长
您现在的位置: 网贝 >> 建站学院 >> ASP技术 >> asp应用 >> 文章正文 用户登录 新用户注册
如何用ASP创建日志文件         ★★★
如何用ASP创建日志文件
相关网站:
作者:佚名 文章来源:网海之贝 点击数: 更新时间:2004-8-29
你是否有时想知道什么人访问你的站点,什么时间,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
%>  
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    相关网站:

    文章 下载 图片
    普通文章身份证校验算法与AS
    普通文章ASP入门教程(留言板
    推荐文章多个绑定多域名的AS
    普通文章不用WinRar将网络空
    普通文章ASP网页模板的应用
    普通文章使用ASP/VBS 调用Go
    普通文章ASP按钮菜单制作实例
    普通文章如何用ASP创建日志文
    推荐文章多个绑定多域名的AS
    推荐文章asp开发规范
    普通文章把手教你写私服列表
    普通文章WEB标准
    普通文章GOOGLE sitemap官方
    普通文章用php定制404错误页
    普通文章WAP(wml)开发问答
    普通文章[组图]PS教程系列:快
    普通文章时使用apache和IIS,
    普通文章[组图]2005年的第一
    推荐文章[组图]彻底掌握IIS6
    推荐文章[组图]CSS 全攻略
    推荐文章各种脚本错误详解!
    推荐文章直接生成XML的Googl
    推荐文章九个常见的错误原因
    推荐文章Win XP家用版也能装
    推荐文章JSP入门初级教程之J
    推荐文章ASP入门及提高
  • 如何用ASP创建日


  • 没有任何图片文章
    (只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    Copyright © 2003-2005 NetBei.com All rights reserved.