如何通过asp动态网页查看网站访问量
我在网站首页添加了记录用户访问IP和时间的代码,代码如下:<%@Language=VBScript%><%response.expires=0%><%dimconndim...
我在网站首页添加了记录用户访问IP和时间的代码,代码如下:
<%@ Language=VBScript %>
<%response.expires = 0 %>
<%
dim conn
dim connstr
connstr="DBQ="+server.mappath("Mydata.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
ip=Request.ServerVariables("REMOTE_ADDR")
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,3,3
rs.addnew
rs("ip")=ip
rs.update
rs.close
set rs=nothing
sql="select ip,time from [ip]"
set rs=conn.execute(sql)
%>
这个代码连接到网站“/Mydata.mdb”数据库,用的是asp+access,但每次查看网站访问量是,都要把数据库文件下载到本地在查看,如何通过asp动态网页查看网站访问量?
数据库浏览页面要由一个表格组成,表格中包括
编号(自动编号)——指向数据库里的ID
访问者ip——指向数据库里的ip
访问时间——指向数据库里的time
rs.CursorLocation = 3
这一行代码有问题,无法读入 展开
<%@ Language=VBScript %>
<%response.expires = 0 %>
<%
dim conn
dim connstr
connstr="DBQ="+server.mappath("Mydata.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
ip=Request.ServerVariables("REMOTE_ADDR")
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,3,3
rs.addnew
rs("ip")=ip
rs.update
rs.close
set rs=nothing
sql="select ip,time from [ip]"
set rs=conn.execute(sql)
%>
这个代码连接到网站“/Mydata.mdb”数据库,用的是asp+access,但每次查看网站访问量是,都要把数据库文件下载到本地在查看,如何通过asp动态网页查看网站访问量?
数据库浏览页面要由一个表格组成,表格中包括
编号(自动编号)——指向数据库里的ID
访问者ip——指向数据库里的ip
访问时间——指向数据库里的time
rs.CursorLocation = 3
这一行代码有问题,无法读入 展开
展开全部
你既然能够保存到数据,那么找个页面把他输出出来不是很容易了~!?
在IP表里加个ID字段(自动编号),呵一个addtime字段(时间类型)!
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,3,3
rs.addnew
rs("ip")=ip
rs.update
rs.close
这段改成
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,3,3
rs.addnew
rs("ip")=ip
rs("addtime")=now()
rs.update
rs.close
然后读取页面文件为(记得是.asp文件):
<%@ Language=VBScript %>
<%response.expires = 0 %>
<%
dim conn
dim connstr
connstr="DBQ="+server.mappath("Mydata.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
ip=Request.ServerVariables("REMOTE_ADDR")
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,1,1
if not rs.eof then%><table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>访问者ip</td>
<td>访问时间</td>
</tr>
<tr>
<td><%=rs("id")%></td>
<td><%=rs("ip")%></td>
<td><%=rs("addtime")%></td>
</tr>
</table>
<%else%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">当前无记录!</td>
</tr>
</table>
<%end if%>
在IP表里加个ID字段(自动编号),呵一个addtime字段(时间类型)!
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,3,3
rs.addnew
rs("ip")=ip
rs.update
rs.close
这段改成
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,3,3
rs.addnew
rs("ip")=ip
rs("addtime")=now()
rs.update
rs.close
然后读取页面文件为(记得是.asp文件):
<%@ Language=VBScript %>
<%response.expires = 0 %>
<%
dim conn
dim connstr
connstr="DBQ="+server.mappath("Mydata.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
ip=Request.ServerVariables("REMOTE_ADDR")
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,1,1
if not rs.eof then%><table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>访问者ip</td>
<td>访问时间</td>
</tr>
<tr>
<td><%=rs("id")%></td>
<td><%=rs("ip")%></td>
<td><%=rs("addtime")%></td>
</tr>
</table>
<%else%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">当前无记录!</td>
</tr>
</table>
<%end if%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%
dim conn
dim connstr
connstr="DBQ="+server.mappath("Mydata.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,1,1
dim i,intPage,page,pre,last,filepath
rs.PageSize =20
rs.CursorLocation = 3
rs.Open sql,connb,0,2,1
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="600" border="1" align="center">
<tr>
<td width="125">序号</td>
<td width="169">IP</td>
<td width="184">时间</td>
</tr>
<%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%>
<tr>
<td><%=rs("id")%></td>
<td><%=rs("ip")%></td>
<td><%=rs("time")%></td>
</tr>
<%
rs.movenext
next
%>
</table>
<table width="600" border="1" align="center" cellpadding="2" cellspacing="1" bordercolorlight="#808080" bordercolordark="#ffffff" bgcolor="#F3FAEB">
<tr>
<%if rs.pagecount > 0 then%>
<td width="13%" align="left"><div align="right">当前页<%=intpage%>/<%=rs.PageCount%></div></td>
<%else%>
<td width="20%" align="left"><div align="right">当前页0/0</div></td>
<%end if%>
<td align="left"><div align="right"><a href="list.asp?page=1">首页</a> |
<%if pre then%>
<a href="list.asp?page=<%=intpage -1%>">上页</a> |
<%end if%>
<%if last then%>
<a href="list.asp?page=<%=intpage +1%>">下页</a> |
<%end if%>
<a href="list.asp?page=<%=rs.PageCount%>">尾页</a> | <%=rs.recordcount%> 条记录 | 转到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="list.asp?page=<%=i%>" selected="selected"><%=i%></option>
<%else%>
<option value="list.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>
页</font> </div></td>
</tr>
</table>
</body>
</html>
把上面的代码保存为ASP格式的文件就可以了
dim conn
dim connstr
connstr="DBQ="+server.mappath("Mydata.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ip]",conn,1,1
dim i,intPage,page,pre,last,filepath
rs.PageSize =20
rs.CursorLocation = 3
rs.Open sql,connb,0,2,1
pre = true
last = true
page = trim(Request.QueryString("page"))
if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="600" border="1" align="center">
<tr>
<td width="125">序号</td>
<td width="169">IP</td>
<td width="184">时间</td>
</tr>
<%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%>
<tr>
<td><%=rs("id")%></td>
<td><%=rs("ip")%></td>
<td><%=rs("time")%></td>
</tr>
<%
rs.movenext
next
%>
</table>
<table width="600" border="1" align="center" cellpadding="2" cellspacing="1" bordercolorlight="#808080" bordercolordark="#ffffff" bgcolor="#F3FAEB">
<tr>
<%if rs.pagecount > 0 then%>
<td width="13%" align="left"><div align="right">当前页<%=intpage%>/<%=rs.PageCount%></div></td>
<%else%>
<td width="20%" align="left"><div align="right">当前页0/0</div></td>
<%end if%>
<td align="left"><div align="right"><a href="list.asp?page=1">首页</a> |
<%if pre then%>
<a href="list.asp?page=<%=intpage -1%>">上页</a> |
<%end if%>
<%if last then%>
<a href="list.asp?page=<%=intpage +1%>">下页</a> |
<%end if%>
<a href="list.asp?page=<%=rs.PageCount%>">尾页</a> | <%=rs.recordcount%> 条记录 | 转到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="list.asp?page=<%=i%>" selected="selected"><%=i%></option>
<%else%>
<option value="list.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>
页</font> </div></td>
</tr>
</table>
</body>
</html>
把上面的代码保存为ASP格式的文件就可以了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询