Response.Write "<html><body>"
‘======***表单提交后:***======
if Request.ServerVariables("REQUEST_METHOD")="POST" then
Dim founderr,callform,msg
founderr = false ‘是否有错误发生
callform = false ‘是否调用表单
msg = "" ‘提示信息
‘==============验证码验证开始===========
dim sessionCode
sessionCode = session("chkCode")
session("chkCode") = ""
CheckCode = trim(Request.Form("chkcode"))
if CheckCode = "" then
msg = msg + "<li>请填写验证码"
founderr = true
callform = true
elseif cstr(CheckCode) <> cstr(sessionCode) then
msg = msg + "<li>验证码不正确"
founderr = true
callform = true
end if
‘==================验证码验证结束============
if founderr = true then
call message("500")
if callform = true then call myform()
else
msg = "<li>操作成功!"
call message("500")
end if
‘======***页面初始化(表单提交前)***======
else
CheckCode = ""
call myform()
end if
Response.Write "</body></html>"
REM 子过程,定义表单
Sub myform()
Response.Write "<table width=500 border=1 cellspacing=0 cellpadding=5 align=center>"&_
"<form name=form1 method=post action=post.asp>"&_
"<tr height=30><td rowspan=2 width=100 align=center>验证码</td>"&_
"<td><input type=text name=chkcode size=10> "&_
getChkCode()&"</td></tr>"&_
"<tr height=30><td>请填写文本框右侧的验证码</td></tr>"&_
"<tr height=30><td colspan=2 align=center>"&_
"<input type=submit name=Submit value=提交></td></tr>"&_
"</form></table>"
end Sub
Rem 子函数,生成验证码(四位随机数)
function getChkCode()
dim ranNum
randomize
ranNum=int(9000*rnd)+1000
session("chkCode") = ranNum
getChkCode = ranNum
end function
Rem 提示信息
sub message(w)
Response.Write "<table width="&w&" border=1 cellspacing=0 cellpadding=5 align=center>"&_
"<tr height=30><td>提示信息</td></tr>"&_
"<tr valign=top><td style=""color:red;"">"&msg&"</td></tr></table>"
end sub
%>
<%
‘**********************************************
‘* NAME:checkcode.asp *
‘* CODE:netops(www.netop.cc) *
‘* USE:生成xbm格式的验证码 *
‘* TIME:2005.7 *
‘**********************************************
on error resume next
dim i
dim countdata
countdata="1234567890"
dim rou,chkcode,chklen
chkcode=""
chklen = 4
randomize
for i=1 to 4
rou = int(rnd*10)
chkcode = chkcode + cstr(rou)
next
dim iCharWidth,iCharHeight,theBit,theNum,iRow,k,theOffset
dim imageStr
imageStr = ""
iCharWidth = 8
iCharHeight= 10*1
Response.ContentType ="image/x-xbitmap"
Response.Expires =0
Response.Write "#define counter_width "&iCharWidth*chklen&chr(13) & chr(10)
Response.Write "#define counter_height "&iCharHeight&chr(13) & chr(10)
Response.Write "static unsigned char counter_bits[]={"
for iRow=0 to iCharHeight-1
for i=1 to chklen
theBit=mid(chkcode,i,1)
k=0
do while k<ubound(strDigits)
if strDigits(k) = theBit then exit do
k=k+iCharHeight+1
loop
if k>=ubound(strDigits) then k=0
theOffset = k + 1
imageStr = imageStr + (strDigits(theOffset+iRow))&","
next
next