验证码示例:
<%
if isempty(session("getcode")) or session("getcode") <> ucase(request.form("form_code")) then
response.write "验证码输入错误"
response.end
else
session("getcode") = empty " 清空session
response.write "验证码输入正确"
response.end
end if
%>
验证码代码:
<%
option explicit " 显示声明
class com_gifcode_class
"""""""""""""""""""""""""""""""""""""""""""""
" author: layen support@ssaw.net 84815733(qq)
" thanks: laomi, laomiao, netrube
" 2006-01-02
"""""""""""""""""""""""""""""""""""""""""""""
public noisy, count, width, height, angle, offset, border
private graph(), margin(3)
private sub class_initialize()
randomize
noisy = 16 " 干扰点出现的概率
count = 4 " 字符数量
width = 80 " 图片宽度
height = 20 " 图片高度
angle = 2 " 角度随机变化量
offset = 20 " 偏移随机变化量
border = 1 " 边框大小
end sub
public function create()
const ccharset = "123456789"
dim i, x, y
dim vvalidcode : vvalidcode = ""
dim vindex
redim graph(width-1, height-1)
for i = 0 to count - 1
vindex = int(rnd * len(ccharset))
vvalidcode = vvalidcode + mid(ccharset, vindex+1 , 1)
setdraw vindex, i
next
create = vvalidcode
end function
sub setdot(px, py)
if px * (width-px-1) >= 0 and py * (height-py-1) >= 0 then
graph(px, py) = 1
end if
end sub
public sub setdraw(pindex, pnumber)
" 字符数据
dim dotdata(8)
dotdata(0) = array(30, 15, 50, 1, 50, 100)
dotdata(1) = array(1 ,34 ,30 ,1 ,71, 1, 100, 34, 1, 100, 93, 100, 100, 86)
dotdata(2) = array(1, 1, 100, 1, 42, 42, 100, 70, 50, 100, 1, 70)
dotdata(3) = array(100, 73, 6, 73, 75, 6, 75, 100)
dotdata(4) = array(100, 1, 1, 1, 1, 50, 50, 35, 100, 55, 100, 80, 50, 100, 1, 95)
dotdata(5) = array(100, 20, 70, 1, 20, 1, 1, 30, 1, 80, 30, 100, 70, 100, 100, 80, _ 100, 60, 70, 50, 30, 50, 1, 60)
dotdata(6) = array(6, 26, 6, 6, 100, 6, 53, 100)
dotdata(7) = array(100, 30, 100, 20, 70, 1, 30, 1, 1, 20, 1, 30, 100, 70, 100, 80, _ 70, 100, 30, 100, 1, 80, 1, 70, 100, 30)
dotdata(8) = array(1, 80, 30, 100, 80, 100, 100, 70, 100, 20, 70, 1, 30, 1, 1, 20, _ 1, 40, 30, 50, 70, 50, 100, 40)
dim vextent : vextent = width / count
margin(0) = border + vextent * (rnd * offset) / 100 + margin(1)
margin(1) = vextent * (pnumber + 1) - border - vextent * (rnd * offset) / 100
margin(2) = border + height * (rnd * offset) / 100
margin(3) = height - border - height * (rnd * offset) / 100
dim vstartx, vendx, vstarty, vendy
dim vwidth, vheight, vdx, vdy, vdeltat
dim vangle, vlength
vwidth = int(margin(1) - margin(0))
vheight = int(margin(3) - margin(2))
" 起始坐标
vstartx = int((dotdata(pindex)(0)-1) * vwidth / 100)
vstarty = int((dotdata(pindex)(1)-1) * vheight / 100)
dim i, j
for i = 1 to ubound(dotdata(pindex), 1)/2
if dotdata(pindex)(2*i-2) <> 0 and dotdata(pindex)(2*i) <> 0 then
" 终点坐标
vendx = (dotdata(pindex)(2*i)-1) * vwidth / 100
vendy = (dotdata(pindex)(2*i+1)-1) * vheight / 100
" 横向差距
vdx = vendx - vstartx
" 纵向差距
vdy = vendy - vstarty
" 倾斜角度
if vdx = 0 then
vangle = sgn(vdy) * 3.14/2
else
vangle = atn(vdy / vdx)
end if
" 两坐标距离
if sin(vangle) = 0 then
vlength = vdx
else
vlength = vdy / sin(vangle)
end if
" 随机转动角度
vangle = vangle + (rnd - 0.5) * 2 * angle * 3.14 * 2 / 100
vdx = int(cos(vangle) * vlength)
vdy = int(sin(vangle) * vlength)
if abs(vdx) > abs(vdy) then vdeltat = abs(vdx) else vdeltat = abs(vdy)
for j = 1 to vdeltat