编写“公平”的ASP图形计数器
点击次数:25 次 发布日期:2008-11-26 17:15:39 作者:源代码网
|
我认为要防止上网用户连续按下“刷新”计数器也连续增加的问题,最好的办法就是利用ASP的Session对象,我们可以借助Session对象首先判断该用户是否为新连接者,如果是,那么 IsEmpty(Session("hasbeenConnected"))=True,也就是说,Session("hasbeenConnected")是空的。那么,运行程序,使计数器加1,然后将该用户的Session("hasbeenConnected")设置为True,也就是说,这个用户已经不是新的连接者,无论他怎么连续按下“刷新”按钮,计数器也不会再增加。 结合《编写ASP图形计数器》一文,最后的站点计数器的源程序应该是: <html> <head> …… </head> <body> <%dim tms,counter,countlen dim images(20) h1="<p><font color="#8000ff">这是一个ASP计数器</font></p>" If IsEmpty(Session("hasbeenConnected")) then set rs=server.createobject("adodb.recordset") application.lock rs.open "update aspcount set countss=countss+1","dsn=userdbs",3,3 application.unlock Session("hasbeenConnected")=True End If set rs=server.createobject("adodb.recordset") rs.open "select * from aspcount","dsn=userdbs",3,3 rs.movefirst counter=rs(0) countlen=len(counter) tms="<h1><font color="#8000ff">您是第</font>"&&counter&&"<font color="#8000ff">位访问者!</font></h1>" response.write(tms) for i=1 to countlen images(i)="<img src="http://www.zzchn.com/edu/20070912/ && mid(counter,i,1) && ".gif></img>" next response.write images(1)&&images(2)&&images(3)&&images(4)&&images(5)&&images(6)&&images(7) rs.Close %> </body> </html> 源代码网供稿. |
