如何轻松打造ASP计数器

精贴 置顶
1994 0

以下介绍用数据库实现简单计数器
'下面存为count.asp
<%
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& Server.MapPath("count.mdb")
%>
<%on error resume next%>
<%sql="update count set hit=hit+1%><%conn.Execute(sql)%>
<%sql = "select * from count
set rs=conn.execute(sql)
%>
<%
'更新每周每日数据
lasthit=rs("lasthit")
tdate=year(Now()) & "-" & month(Now()) & "-" & day(Now())
if trim(lasthit)=trim(tdate) then
sql="update site set dayhit=dayhit+1 where id="&request("id")
conn.Execute(sql)
' response.write "success"
else
sql="update site set dayhit=1 where id="&request("id")
conn.Execute(sql)
' response.write "error"
end if
sql="update site set lasthit='"&tdate&"' where ID="&request("id")
conn.Execute(sql)


p_year=CInt(year(Now()))-CInt(year(lasthit))
p_month=CInt(month(Now()))-CInt(month(lasthit))
p_day=CInt(day(Now()))-CInt(day(lasthit))
period_time=((p_year*12+p_month)*30+p_day)
if cint(period_time)=<cint(7) then
sql="update site set weekhit=weekhit+1 where id="&request("id")
conn.Execute(sql)
else
sql="update site set weekhit=1 where id="&request("id")
conn.Execute(sql)
end if
%>
document.write('<tr><td width="100%">今日访问<%=rs("dayhit")%>次,本周访问<%=rs("weekhit")%>次,总访问<%=rs("hit")%>次</td></tr>');
<%rs.close
set rs=nothing%>


'用<script language="JavaScript1.1" src="count.asp"></script>在要统计的页面调用即可.

建立数据库:建一个count的MDB库,再建一个表count,表中字段为
hit 数字型
dayhit 数字型
weekhit 数字型
lasthit 日期型

  • 没有任何评论
今日天气 ···

···

···

···

热门排行
CSS cursor鼠标样式一览表 2012-06-25
.NET后台写JS代码 2011-11-03
网站地址多出jdfwkey的问题解析及... 2010-08-25
数据库xxx的日志已满,请备份该数... 2013-07-19
百度、google、Yahoo网站地图制作... 2011-01-30
<a>标签的伪类书写顺序问题... 2010-09-04
什么是长尾关键词? 2010-09-24
CEO名言 2010-08-31
Mysql 主从数据库同步 2010-09-12
用ASP实现网页BBS 2010-11-01
博主推荐
本个人博客微信公众平台上线啦~~... 2013-10-13
饼哥网络互联上线啦~~要买域名空... 2013-09-20
网站title标题如何正确修改不会被... 2013-08-26
饼哥通讯录系统上线啦,欢迎大家... 2013-08-24
ASP .NET MYSQL 的简单分页 并不... 2013-08-19
网站有弹窗广告这样的站点,百度... 2013-08-17
做淘宝SEO优化需要注意的8大问题 2013-08-17
淘宝网怎么做SEO优化 2013-08-17
站长们要学习的“苍井空精神” 2013-08-17
苹果公司今日发布了iOS 7第五个开... 2013-08-07
随便看看
路由器的口令设置 2010-11-05
android屏幕触摸事件机制 2013-06-27
精彩实用:Win XP热门技巧十招 2010-11-07
如何让路由器摆脱安全困扰 2010-11-23
php怎么获取当前页面的后缀文件名... 2010-09-12
网站地址多出jdfwkey的问题解析及... 2010-08-25
关于怎么判断手机ROOT 2013-06-19
各类数值型数据间的混合运算 2010-10-16
ASP内建对象Application和Sessio... 2010-10-23
ASP.NET中 Repeater嵌套应用 2013-07-01
RSS新闻
传媒新闻
CSDN
八卦新闻
女性新闻
台湾新闻
互联网
军事-新浪博客
IT-新浪博客
汽车新闻
游戏新闻
国际新闻
国内新闻
体育新闻
我的微博
北京 上海 杭州 深圳 广州 成都