4.9 如何轻松打造ASP计数器

2016-02-19 14:03 3 1 收藏

下面这个4.9 如何轻松打造ASP计数器教程由图老师小编精心推荐选出,过程简单易学超容易上手,喜欢就要赶紧get起来哦!

【 tulaoshi.com - Web开发 】

以下介绍用数据库实现简单计数器
'下面存为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>在要统计的页面调用即可.

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

 

来源:https://www.tulaoshi.com/n/20160219/1606053.html

延伸阅读
标签: PHP
  --------------------------------------------------------------------------------   请保持文章的完整性   --------------------------------------------------------------------------------------   <?   //counter.php All rights reserved http://sports98.126.com   ...
标签: Java JAVA基础
  计数器是一般网站必备的东东,别小看它了,每当站长看着小小计数器上的数字飞速增长的时候,感觉实在是好极了。以前我们用cgi、asp来写计数器,这方面的文章很多了,在这里,我们将会采用目前比较流行的jsp技术演示如何做一个计数器。 其中我们用到了两个文件,test.jsp文件用于在浏览器中运行,counter.java是后台的一个小java bean程...
标签: Java JAVA基础
  <!-- JSP-Hitcounter counts sessions. Copyright (C) 2000 Jesper Schmitz Mouridsen. Visit www.webappcabaret/jsm2/webapps.jsp?find=jsphcs for more info. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software...
标签: ASP
  网页计数器DIY 随着网络大行其道,网页计数器也流行起来。事实上大多数网站均有网页计数器,用以反映该网站的访问量。计数器的来源很广,Frontpage等网页编辑器自带了网页计数器,有的站点也提供免费的计数器下载。其实熟悉了ASP编程后,自己做一个计数器很容易。下面介绍一种实现方法。 计数器原理是:在第一次使用网页时置初始值1,以...
标签: PHP
  1)文本计数器 <?php $countfile="/count.txt";  //设置保存数据的文件 if (!file_exists($countfile)){//判断文件是否存在 exec( "echo 0 $countfile"); } $fp = fopen($countfile,"rw"); $length=filesize($countfile); $num = fgets($fp,$length); $num += 1; exec( "rm -rf $...

经验教程

346

收藏

68
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部