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
>
查看全文
相关阅读:
poj_2506_Tiling_201407211555
poj_2524_Ubiquitous Religions_201407211506
poj_2586_Y2K Accounting Bug_201407211318
poj_3006_Dirichlet's Theorem on Arithmetic Progressions_201407041030
POJ训练计划
nyoj_10_skiing_201405181748
nyoj_308_Substring_201405091611
nyoj_205_求余数_201404271630
hdu_2082_找单词_201404271536
nyoj_176_队花的烦恼二_201404262008
原文地址:https://www.cnblogs.com/Ja/p/158265.html
最新文章
90%工程师都说不明白的上下文管理器
还不知道如何把Python打包成exe吗?
对KMP算法的理解
回文串专题总结
关于python list乘法的坑
Leetcode 79 单词搜索
【复习笔记】最优化方法
【复习笔记】最优化方法
【复习笔记】最优化方法
【复习笔记】最优化方法
热门文章
hdu 1276 士兵排队问题(队列的练习使用)
hdu 1862
nyoj 72 399
nojy 198 数数
nyoj 5470 奇怪的排序
hdu 1106 排序
nyoj 7 最短路径问题
hdu 3006 the number of set
hdu 2115 I love this game
hdu 3782 XXX定律 与位运算相关
Copyright © 2011-2022 走看看