asp页面记录IP

   Dim userip,objstr,objFSO,objText,objFile

//获取客户端的登录IP,
   userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If userip = "" Then
      userip = Request.ServerVariables("REMOTE_ADDR")
    End If

  Set objFSO = CreateObject("Scripting.FileSystemObject")

//在log文件夹是否存在当天的日志文件,红色部分不太明白,但是这句不写就出现运行时错误
objFile = "log/ipLog" & date() & ".txt"
objFile = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")),InStrRev(Server.Mappath(Request.ServerVariables("PATH_INFO")), "\")) & objFile

 //若文件存在则向该文件追加记录,若不存在在新建并添加记录

IF objFSO.FileExists(objFile) then
Set objText = objFSO.OpenTextFile(objFile,8,true)
objText.WriteLine(now & "  "& session("admin") & "  " & userip)
else
objText = objFSO.CreateTextFile(objFile)
objText.WriteLine(userip)
 end if

 

 

 

posted @ 2010-08-24 16:41  肖湘  阅读(1212)  评论(0编辑  收藏  举报