首页 >> 读书频道 >> 电脑 >> 来访者地址统计,很好的一个程序!
 
· 如何用ASP编写网站统计
· 如何用ASP编写网站统计
· 如何用ASP编写网站统计
· 如何用ASP编写网站统计
· 货币大写转换函数的更新
· 一种函数的计算方法并给出
· 计算当前日期是任意时间段
· 用正则表达式突出显示字符
· 把长的数字用逗号隔开显示
· 遍历目录以及目录下文件的
· 转换字符串单词的第一个字
· 计算文件下载时间
 
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 红楼梦:120回全本[清
· 武林寓言故事
· 2006高考录取规则
· 首批中国世界名牌产品和2
· 济南美食大全
· 管理三十六计
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

来访者地址统计,很好的一个程序!


查看有无更新版本

关键字:代码乐园 2006-8-28

 

In your global.asa, Session_OnStart, add:
'Update user database
set conntemp=server.createobject("adodb.connection")
cnpath="DBQ=" & server.mappath
("/stevesmith/data/timesheet.mdb")
conntemp.Open "DRIVER={Microsoft Access Driver (*.mdb)}; "
& cnpath
sqlString = "INSERT INTO user_log " & _
"
(user_id,log_date,action_code,browser,ip_address) " & _
" VALUES ('Unknown',now,'L','" & _
Request.ServerVariables("HTTP_USER_AGENT") & "','"
& _
Request.ServerVariables("REMOTE_HOST") & "')"
Set logRS=conntemp.execute(sqlString)
Set logRS=nothing


Include on any page whose hits you wish to track:
'Update pagelog
Dim hdrconntemp
Dim hdrcnpath
Dim hdrsqlString
Dim hdrlogRS
set hdrconntemp=server.createobject("adodb.connection")
hdrcnpath="DBQ=" & server.mappath
("/stevesmith/data/timesheet.mdb")
hdrconntemp.Open "DRIVER={Microsoft Access Driver
(*.mdb)}; " & hdrcnpath
hdrsqlString = "INSERT INTO page_log " & _
" (page,log_date,action_code,browser,ip_address) "
& _
" VALUES ('" & Request.ServerVariables
("SCRIPT_NAME") & "',now,'L','" & _
Request.ServerVariables("HTTP_USER_AGENT") & "','"
& _
Request.ServerVariables("REMOTE_HOST") & "')"
Set hdrlogRS= hdrconntemp.execute(hdrsqlString)
Set hdrlogRS=nothing

Naturally, you'll need to create the tables and the DSN yourself for
your own site. The table setup should be fairly obvious from the
INSERT statements. I called the tables user_log and page_log. Lastly,
you will need to display your statistics somewhere. Here is the
source code for usage.asp:

1<% OPTION EXPLICIT %>
2<!--#include virtual="stevesmith/top.asp"-->
3<%
4' Initialize Variables
5Dim MyServer 'Address Server Portion
6Dim MyPath 'Address Path Portion
7Dim MySelf 'Full HTTP Address
8Dim starttime 'Time page began
9Dim objConnect 'Default Connection Object
10Dim cnpath 'Connection path
11Dim objCmd 'Default Command Object
12Dim objRst 'Default Recordset Object
13Dim total 'Total logins
14Dim totalhits 'Total page hits
15Dim successfullogins 'Number of Successful logins
16Dim failedlogins 'Number of failed logins
17Dim IE 'Number of Internet Explorer Hits
18Dim Net 'Number of Netscape Navigator Hits
19Dim I 'Loop control variable
20Dim hourhits 'Hits in last hour
21Dim hourusers 'Users in last hour
22Dim dayhits 'Hits in last day
23Dim dayusers 'Users in last day
24Dim weekhits 'Hits in last week
25Dim weekusers 'Users in last week
26Dim monthhits 'Hits in last month
27Dim monthusers 'Users in last month
28Dim tmpDate,tmpDate2 'Date
29 
30 MyServer=Request.ServerVariables("SERVER_NAME")
31 MyPath=Request.ServerVariables("SCRIPT_NAME")
32 MySelf="HTTP://" & MyServer & MyPath
33 %>
34 <html>
35 <head>
36 <title>Usage</title>
37 <meta HTTP-EQUIV="REFRESH" CONTENT="300;<%=Myself%>">
38 </head>
39 <body background="http://<%=Request.ServerVariables
("SERVER_NAME")%>/stevesmith/images/whtmarb.jpg">
40 <a HREF="http://<%=Request.ServerVariables("SERVER_NAME")%
>/stevesmith/index.asp">
41 <img SRC="http://<%=Request.ServerVariables("SERVER_NAME")%
>/stevesmith/images/return.gif"
42 ALIGN="LEFT" ALT="Return to Stevenator's ASP Page" WIDTH="40"
HEIGHT="40"></a>
43 
44 <center><h1>Usage (May 1998 to February 1999)</h1></center>
45 <%
46 starttime = now
47 
48'Establish connection
49Set objConnect = Server.CreateObject("ADODB.Connection")
50cnpath="DBQ=" & server.mappath("/stevesmith/data/timesheet.mdb")
51objConnect.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " &
cnpath
52 
53'Create Command object
54Set objCmd = Server.CreateObject("ADODB.Command")
55Set objCmd.ActiveConnection=objConnect
56objCmd.CommandType = adCmdText
57 
58'Set up objRst
59Set objRst = Server.CreateObject("ADODB.Recordset")
60Set objRst.ActiveConnection=objConnect
61Set objRst.Source = objCmd
62 
63'Get users/hits in last hour
64tmpDate = DateAdd("h",-1,now())
65objCmd.CommandText = "SELECT count(user_id) as cnt FROM
user_log " & _
66" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
67objRst.Open
68hourusers = objRst("cnt")
69objRst.Close
70objCmd.CommandText = "SELECT count(ip_address) as cnt FROM
page_log " & _
71" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
72objRst.Open
73hourhits = objRst("cnt")
74objRst.Close
75
76'Get users/hits in last day
77tmpDate = DateAdd("d",-1,now())
78objCmd.CommandText = "SELECT count(user_id) as cnt FROM
user_log " & _
79" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
80objRst.Open
81dayusers = objRst("cnt")
82objRst.Close
83objCmd.CommandText = "SELECT count(ip_address) as cnt FROM
page_log " & _
84" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
85objRst.Open
86dayhits = objRst("cnt")
87objRst.Close
88
89'Get users/hits in last week
90tmpDate = DateAdd("d",-7,now())
91objCmd.CommandText = "SELECT count(user_id) as cnt FROM
user_log " & _
92" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
93objRst.Open
94weekusers = objRst("cnt")
95objRst.Close
96objCmd.CommandText = "SELECT count(ip_address) as cnt FROM
page_log " & _
97" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
98objRst.Open
99weekhits = objRst("cnt")
100objRst.Close
101
102'Get users/hits in last month
103tmpDate = DateAdd("m",-1,now())
104objCmd.CommandText = "SELECT count(user_id) as cnt FROM
user_log " & _
105" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
106objRst.Open
107monthusers = objRst("cnt")
108objRst.Close
109objCmd.CommandText = "SELECT count(ip_address) as cnt FROM
page_log " & _
110" WHERE log_date between #" & now & "# AND #"& tmpDate & "#"
111objRst.Open
112monthhits = objRst("cnt")
113objRst.Close
114 
115objCmd.CommandText = "SELECT count(user_id) as cnt FROM
user_log " & _
116" WHERE action_code = 'L'"
117objRst.Open
118total = objRst("cnt")
119objRst.Close
120objCmd.CommandText = "SELECT count(*) as cnt" & _
121" FROM page_log "
122objRst.Open
123totalhits = objRst("cnt")
124 %>
125 <center>
126 <b>Your IP: <font COLOR="RED"><%=Session("IP")%></font></b>
127 <table BORDER bgColor="#f3efd0">
128 <tr bgColor="#dfcba0">
129<th>Item</th>
130<th>Last Hour</th>
131<th>Last Day</th>
132<th>Last Week</th>
133<th>Last Month</th>
134<th>Total</th>
135 </tr>
136 <tr>
137 <td align="left"><b>Logins:</b></td>
138 <td><%=hourusers%></td>
139 <td><%=dayusers%></td>
140 <td><%=weekusers%></td>
141 <td><%=monthusers%></td>
142 <td align="CENTER"><font color="red"><%=total%></font></td>
143 </tr>
144 <tr>
145 <td align="left"><b>Page Hits:</b></td>
146 <td><%=hourhits%></td>
147 <td><%=dayhits%></td>
148 <td><%=weekhits%></td>
149 <td><%=monthhits%></td>
150 <td align="CENTER"><font color="red"><%=totalhits%></font></td>
151 </tr>
152 
153 </table>
154 <hr>
155 <!-- Display Total Hits by UserID, with IP Address -->
156 <%
157objRst.Close
158objCmd.CommandText = "SELECT count(user_id) as cnt, user_id,
ip_address, max(log_date) as ld" & _
159" FROM user_log WHERE " & _
160" action_code = 'L' " & _
161" GROUP BY ip_address,user_id " & _
162" ORDER BY ip_address "
163objRst.Open
164 %>
165 <table border>
166 <caption><b>Hits by User</b></caption>
167 <tr bgColor="#dfcba0">
168 <td><b>Name</b></td>
169 <td><b>IP Address</b></td>
170 <td><b># of Logins</b></td>
171 <td><b>Last Login</b></td>
172 </tr>
173 <tr>
174 <td COLSPAN="4"><font COLOR="RED">Chopped for Brevity. Source
code available
175 <a
HREF="http://www.aspalliance.com/stevesmith/samples/sitestats.asp">her
e.</a></font></td>
176 </tr>
177 <!--<%' Do While Not objRst.EOF%><tr bgColor="#f3efd0"><td
align="CENTER"> <%=objRst("user_id")%> </td><td align="CENTER"> <%
=objRst("ip_address")%> </td><td align="CENTER"> <%=objRst("cnt")%> (
<%=fix(CInt(objRst("cnt"))*100/total)%> %) </td><td> <%=objRst("ld")%
></td></tr> <%' objRst.MoveNext' Loop%>-->
178 </table><hr>
179 <!-- Display Total Hits by Page, with IP Address -->
180 <%
181objRst.Close
182objCmd.CommandText = "SELECT count(page) as cnt, page, max
(log_date) as ld" & _
183" FROM page_log WHERE " & _
184" action_code = 'L' " & _
185" GROUP BY page " & _
186" ORDER BY count(page) DESC "
187objRst.Open
188 %>
189 <table border>
190 <caption><b>Hits by Page</b></caption>
191 <tr bgColor="#dfcba0">
192 <td><b>Page</b></td>
193 <td><b># of Hits</b></td>
194 <td><b>Last Hit</b></td>
195 </tr>
196<%
197Do While Not objRst.EOF
198 %>
199 <tr bgColor="#f3efd0">
200 <td align="left">
201<%=objRst("page")%>
202</td>
203 <td align="CENTER">
204<%=objRst("cnt")%>
205(
206<%=fix(CInt(objRst("cnt"))*100/totalhits)%>
207%) </td>
208 <td>
209<%=objRst("ld")%>
210 </td>
211 </tr>
212<%
213objRst.MoveNext
214Loop
215 %>
216
217 </table>
218 
219 <hr>
220 <!-- Display total hits by Browser type -->
221 <%
222objRst.Close
223objCmd.CommandText = "SELECT browser, count(*) as cnt " & _
224" FROM user_log " & _
225" WHERE browser is not null " & _
226" GROUP BY browser " & _
227" ORDER BY count(browser) desc"
228objRst.Open
229 %>
230 <table border>
231 <caption><b>Hits by
232Browser</b></caption>
233 <tr bgColor="#dfcba0">
234 <td><b>Browser</b></td>
235 <td><b>Hits</b></td>
236 </tr>
237<%
238IE = 0
239Net = 0
240Do While Not objRst.EOF
241If InStr(objRst("browser"),"MSIE") Then
242IE = IE + CInt(objRst("cnt"))
243ElseIf InStr(objRst("browser"),"Mozilla") Then
244Net = Net + CInt(objRst("cnt"))
245End If
246 %>
247 <tr bgColor="#f3efd0">
248 <td>
249<%=objRst("browser")%>
250</td>
251 <td>
252<%=objRst("cnt")%>
253(
254<%=fix(CInt(objRst("cnt"))*100/total)%>
255%)
256 </td>
257 </tr>
258<%
259objRst.MoveNext
260Loop
261 %>
262
263 </table>
264 <hr>
265 <!-- Display percent Explorer vs Netscape users -->
266 <table BORDER BGCOLOR="#f3efd0">
267 <caption><b>Hits by
268Browser</b></caption>
269 <tr bgColor="#dfcba0">
270 <td><b>Netscape</b></td>
271 <td><b>Explorer</b></td>
272 <td><b>Other</b></td>
273 </tr>
274 
275 <tr>
276 <td>
277<%=Net%>
278(
279<%=fix(Net*100/total)%>
280%)</td>
281 <td>
282<%=IE%>
283(
284<%=fix(IE*100/total)%>
285%)</td>
286 <td>
287<%=total-Net-IE%>
288(
289<%=fix((total-Net-IE)*100/total)%>
290%)</td>
291 </tr>
292 
293 </table>
294 <hr>
295 <!-- Display total hits by IP and browser - what browser does
each user prefer -->
296 <%
297objRst.Close
298objCmd.CommandText = "SELECT ip_address, browser, count(*) as
cnt " & _
299" FROM user_log " & _
300" WHERE action_code = 'L' " & _
301" GROUP BY browser, ip_address " & _
302" ORDER BY ip_address"
303objRst.Open
304 %>
305 <table border>
306 <caption><b>Browser Hits by
307User</b></caption>
308 <tr bgColor="#dfcba0">
309 <td><b>User</b></td>
310 <td><b>Browser</b></td>
311 <td><b>Hits</b></td>
312 </tr>
313 <tr>
314 <td COLSPAN="3"><font COLOR="RED">Chopped for Brevity(10 lines
shown). Source code available
315 <a
HREF="http://www.aspalliance.com/stevesmith/samples/sitestats.asp">her
e.</a></font></td>
316 </tr>
317<%
318I = 0
319Do While I < 10
320I = I + 1
321 %>
322 <tr bgColor="#f3efd0">
323 <td><%=objRst("ip_address")%>
324 </td>
325 <td>
326<%=objRst("browser")%>
327</td>
328 <td>
329<%=objRst("cnt")%>
330(
331<%=fix(CInt(objRst("cnt"))*100/total)%>
332%)
333 </td>
334 </tr>
335<%
336objRst.MoveNext
337Loop
338 %>
339
340 </table>
341 <hr>
342 <!-- Display last ten users and time of use -->
343 <%
344objRst.Close
345objCmd.CommandText = "SELECT ip_address, " & _
346" log_date FROM user_log WHERE " & _
347" action_code = 'L' " & _
348" ORDER BY log_date DESC"
349objRst.Open
350 %>
351 <table border>
352 <caption><b>Last 10
353Users</b></caption>
354 <tr bgColor="#dfcba0">
355 <td> </td>
356 <td><b>Date</b></td>
357 <td><b>IP Address</b></td>
358 </tr>
359<%
360I = 0
361Do While (Not objRst.EOF) AND (I < 10)
362I = I + 1
363 %>
364 <tr bgColor="#f3efd0">
365 <td>
366<%=I%>
367 <td>
368<%=objRst("log_date")%>
369</td>
370 <td>
371<%=objRst("ip_address")%>
372</td>
373 </tr>
374 <% objRst.MoveNext
375Loop %>
376 <!-- Display Total Server time to generate this data -->
377 </table>
378 <b>Total load time:
379 <font color="red">
380 <%=datediff("s",starttime,now)%>
381 </font>seconds</b>
382 </center>
383 <!--#INCLUDE VIRTUAL="/stevesmith/bottom.asp"-->
384 </body>
385 </html>

来访者地址统计,很好的一个程序!

[ 1 ]
来访者地址统计,很好的一个程序! num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑