在HTML页面中实现点击数统计

在文章发布系统中采用服务器端生成静态页面的方法可以有效减轻服务器的负担,特别是对大流量网站非常有效。但是既然生成的是静态页面,生成时是什么样,显示就是什么样了,对于文章常见文章被阅读次数怎么显示呢?

经考虑,可用如下方案解决:
生成静态页面时会产生一个文章的id存到数据库中,那么我们在制作文章的模板的时候就可以在这个文章的id上做文章,文章模板包含以下语句:

1<script src="counter.asp?articleId=```
2=#articleId#
3```"></script>

说明:

在利用模板生成文章时,把"#articleId#"进行模式匹配,替换为新添加的文章的id号。

counter.asp 文件为实现记数的asp文件

 1 
 2
 3'################### 
 4
 5'######开始######### 
 6
 7'BY 王向超 
 8
 9'################### 
10
11dim articleId,sqlStr,hits 
12
13articleId=int(trim(request.querystring("articleId"))) 
14
15sqlStr="update articles set hits=hits+1 where articleId=" & articleId 
16
17'给文章点击数加1 
18
19conn.execute(sqlStr) 
20
21'读出文章点击数 
22
23hits=conn.execute("select hits from articles where articleId=" & articleId)(0) 

'打印出文章点击数

document.write(``` =hits

Published At
Categories with Web编程
Tagged with
comments powered by Disqus