zoukankan
html css js c++ java
[JavaScript]给自己的网站添加简单文本日志
1.用于记录日志的文件 log.asp,另外需要建立一个用于保存日志文件的文件夹logs。
log.asp文件的代码如下:
<
script language
=
"
javascript
"
runat
=
"
server
"
>
var
fso
=
new
ActiveXObject(
"
Scripting.FileSystemObject
"
);
var
dt
=
new
Date();
strDate
=
String(dt.getMonth())
+
String(dt.getDate());
var
strFileName
=
"
logs\\log
"
+
strDate
+
"
.htm
"
;
var
filename
=
Server.MapPath(strFileName);
var
logFile;
if
(fso.FileExists(filename))
{
logFile
=
fso.OpenTextFile(filename,
8
);
}
else
{
logFile
=
fso.CreateTextFile(filename,
true
);
}
var
str
=
"
<br>
"
+
String(dt.getYear())
+
"
年
"
+
String(dt.getMonth())
+
"
月
"
+
String(dt.getDate())
+
"
日
"
+
String(dt.getHours())
+
"
:
"
+
String(dt.getMinutes())
+
"
:
"
+
String(dt.getSeconds())
+
"
"
+
Request.ServerVariables(
"
REMOTE_ADDR
"
)
+
"
"
+
Request.ServerVariables(
"
URL
"
)
+
"
"
+
Request.ServerVariables(
"
HTTP_USER_AGENT
"
);
logFile.WriteLine(str);
logFile.Close();
delete
logFile;
delete
fso;
</
script
>
2.在需要记录访问的页面上,添加如下代码:
<!--
#include file
=
"
log.asp
"
//
-->
3.这样,就可以将访问者的访问时间、访问的页面以及访问者使用的浏览器和操作系统记录下来,方便网站管理者了解访问者的基本情况。
4.用于浏览日志的网页viewlog.asp代码如下:
<%
@LANGUAGE
=
"
JAVASCRIPT
"
CODEPAGE
=
"
936
"
%>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
>
<
title
>
日志
</
title
>
</
head
>
<
body
>
<
div
>
<
font
size
="2"
>
<%
p
=
Request.QueryString(
"
p
"
);
tp
=
"
log
"
+
p
+
"
.htm
"
;
Server.
Execute
(tp);
%>
</
font
>
</
div
>
</
body
>
</
html
>
查看全文
相关阅读:
去深圳办理港澳通行证签注延期
預約申領往來港澳通行證及簽注x
表格选中效果展示
Purchase购物车实例分析
IOS开发基础知识--碎片17
IOS开发基础知识--碎片16
IOS开发基础知识--碎片15
IOS开发基础知识--碎片14
IOS关于LKDBHelper实体对象映射插件运用
IOS开发基础知识--碎片13
原文地址:https://www.cnblogs.com/Ja/p/158265.html
最新文章
Ubuntu apt 安装MySQL的用户名和密码
wide & deep 模型
2016年港澳台研究生招生考试报名注意事项
wpf揭秘
淘宝集运
表(一)、嬰幼兒各階段發展遲緩警訊
video conference s/w
buntu下备份系统的方法
removing-guest-session-at-login-in-ubuntu-14-04
Add task bar to ubuntu
热门文章
windows下尝试编写node模块
GUI相关学习资料
Vision GUI programming products
Easy to use cross-platform 3D engines
direct3d
插座
wpf
机器视觉应用
gevent原理
git
Copyright © 2011-2022 走看看