欢迎光临
我们一直在努力

如何用ASP创建日志文件

建站超值云服务器,限时71元/月

你是否有时想知道什么人访问你的站点,什么时间,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

dont 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

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何用ASP创建日志文件
分享到: 更多 (0)

相关推荐

  • 暂无文章