ASP SCRIPT: 计数器(使用GrapShot组件)

作者:佚名 来源:knowsky.com 时间:2008-11-07 15:36:00 

这个程序将记数器的数字放在ACCESS数据库中,当然你也能用你希望其它的ODBC数据源.这个程序从URL中读取记数信息.如下:

< IMG src="id=MYTEST&seq=default&cells=7" >

参数
id

客户网页的标致(即用户名).每次你用一个新的ID,那么就会有一个新的记录插入数据库中.如果这个ID是原来就存在,那么它的count就增加1.如果你不想让客户自动启动一个ID,而需要注册,那么你就将"自动插入"的值,赋为False.

seq

可选项.用于选择计数器图片的式样,在客户端所显示的图片的名字就为.gif.缺省值"defalut.gif",而且这个"defalut.gif"必须放在当前工作的目录中!

cells

可选项.计数结果显示的位数,缺省是5位(这个值你在程序中,也可以调节) 怎样运行这个程序
把这段程序拷贝到服务器中你想要的地方.

创建一个数据源"Webcounter".这个数据源中必须有个表名字为"main",以下是这个表中的字段:


< table border="1" cellpadding="3" cellspacing="1" >
< tr >
< th >Field< /th >
< th >Type< /th >
< th >Indexed< /th >
< th >Means< /th >
< /tr >
< tr >
< td >ident< /td >
< td >AutoNumber< /td >
< td >Yes< /td >
< td >For your needs< /td >
< /tr >
< tr >
< td >id< /td >
< td >Text< /td >
< td >Yes< /td >
< td >用户名< /td >
< /tr >
< tr >
< td >count< /td >
< td >Number< /td >
< td >No< /td >
< td >计数数字< /td >
< /tr >
< /table >

需要时给数据库赋一个的权限

建立一个存放GIF图形的目录,在这个目录中至少要放一个default.gif的图形组.适当时给这个文件以权限.

给这个目录中放一些能被10整除的数字图形.


< table width="100%" border="1" cellspacing="1" cellpadding="2" >
< tr >
< td bgcolor="#ccffff" >File < b >counter.asp< /b > < /td >
< /tr >
< tr >
< td bgcolor="#ffffcc" >< pre >
< %
Response.ContentType="image/gif"
Response.Expires=0
'The directory where GIF bars are placed. Ends with \
workdir="c:\gifbars\"
'Set this to False if you want to disable auto inserting
'new counter records to database on every hit with unique
'id string
auto_insert=True
id=Trim(Request.QueryString("id"))
seq=Trim(Request.QueryString("seq"))
if seq="" then seq="default"
cells=Trim(Request.QueryString("cells"))
if cells="" then cells=5 else cells=cells*1
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Webcounter"
sql="select count,ident from main where id='" & id & "'"
set rs=conn.Execute(sql)
if not rs.EOF then
count=rs("count")+1
ident=rs("ident")
rs.close()
conn.Execute("update main set count=count+1 where ident=" & ident)
conn.close()
ShowNumbers()
else
rs.close()
if auto_insert=True and id< >"" then
conn.Execute("insert into main (id,count) values ('" & id & "',1)")
count=1
ShowNumbers()
end if
conn.close()
end if

Sub ShowNumbers()
set g=CreateObject("shotgraph.image")
filename=workdir & seq & ".gif"
if g.GetFileDimensions(filename,xsize,ysize,pal)< >1 then Exit Sub
xdigit=xsize\10
g.CreateImage xdigit*cells,ysize,UBound(pal)+1
g.InitClipboard xsize,ysize
g.SelectClipboard True
for i=0 to UBound(pal)
g.SetColor i,pal(i,0),pal(i,1),pal(i,2)
next
g.ReadImage filename,pal,0,0
for i=1 to cells
k=GetDigit(count,cells-i)
g.Copy (i-1)*xdigit,0,xdigit,ysize,k*xdigit,0,"SRCCOPY"
next
Response.BinaryWrite g.GifImage(-1,1,"")
End Sub

Function GetDigit(number,position)
number1=number\(10^position)
tmp=number1\10
GetDigit=number1-tmp*10
End Function

% >
< xmp >
< /pre >
< /td >
< /tr >
< /table >

< hr >< /span >< /td >
< /tr >
< tr >
< td width="50%" > < /td >
< td width="50%" >< br >< /td >
< /tr >
< tr >
< td colspan=2 align="right" >
< img border="0" src=http://www.chinaz.com/Program/Asp/"images/bbstitle.gif" >< a id="hlkAddMsg" href="/AddMsg.aspx?id=234" style="color:red" >发表评论< /a >
< img border="0" src=http://www.chinaz.com/Program/Asp/"images/mail.gif" >< a id="hlkMailTo" href="/MailTo.aspx?id=234" >邮寄本页< /a >
< img border="0" src=http://www.chinaz.com/Program/Asp/"images/print.gif" >< a href="javascript:window.print()" >打印本页< /a >
< img border="0" src=http://www.chinaz.com/Program/Asp/"images/profile.gif" >< a href="javascript:void(null)" onclick="if(!document.execCommand('SaveAs','show.aspx',1)) return false;" >保存本页< /a >
< img border="0" src=http://www.chinaz.com/Program/Asp/"images/ask.gif" >< a href="bbs/index.asp" >您有疑问< /a >
< /td >
< /tr >
< tr bgcolor="#97B9FF" >
< td width="50%" >< b >< font color="#FFFFFF" >相关文章< /font >< /b >< /td >
< td width="50%" >< b >< font color="#FFFFFF" >相关评论< /font >< /b >< /td >
< /tr >
< tr >
< td width="50%" valign="top" >

< /td >
< td width="50%" valign="top" >

< /td >
< /tr >
< tr >
< td width="50%" >
< /td >
< td width="50%" align="right" >< img border="0" src=http://www.chinaz.com/Program/Asp/"images/more.gif" >< a id="hlkRela" >< /a >< /td >
< /tr >
< /table >
< /td >
< /tr >
< /table >
< /td >
< /tr >
< /table >
< /body >
< /html >

标签:
0
投稿

猜你喜欢

  • MySQL Index Condition Pushdown(ICP)性能优化方法实例

    2024-01-19 20:08:25
  • php strstr查找字符串中是否包含某些字符的查找函数

    2023-11-17 01:42:23
  • 浅谈Django中的数据库模型类-models.py(一对一的关系)

    2024-01-24 18:32:11
  • python被修饰的函数消失问题解决(基于wraps函数)

    2021-07-22 17:32:34
  • Python日期的加减等操作的示例

    2021-10-06 14:28:14
  • pip 安装库比较慢的解决方法(国内镜像)

    2022-09-30 04:02:29
  • javascript 得到变量类型的函数

    2024-04-30 08:53:34
  • python使用PIL剪切和拼接图片

    2022-06-26 07:41:55
  • tensorflow学习笔记之简单的神经网络训练和测试

    2021-02-18 20:28:14
  • SymPy库关于矩阵的基本操作和运算

    2022-10-30 12:23:55
  • python GUI库图形界面开发之PyQt5控件数据拖曳Drag与Drop详细使用方法与实例

    2022-04-19 04:22:39
  • 常用SQL功能语句

    2024-01-15 17:08:58
  • python二维图制作的实例代码

    2021-09-17 21:29:35
  • pytorch 实现tensor与numpy数组转换

    2022-02-07 16:06:44
  • MySQL中in和exists区别详解

    2024-01-19 20:55:10
  • asp如何在网上查找链接?

    2010-06-22 21:10:00
  • 在Python反编译中批量pyc转 py的实现代码

    2023-08-11 20:21:04
  • 创建数据表/创建列的一些asp函数

    2008-06-24 12:21:00
  • jQuery打造动态下滑菜单

    2010-04-20 14:50:00
  • MySQL 回表,覆盖索引,索引下推

    2024-01-21 12:56:59
  • asp之家 网络编程 m.aspxhome.com