动网论坛验证码改进 加法验证码(ASPJpeg版)
565
2012-10-11

 

<% 
'=============================================================================
'动网论坛加法验证码(ASPJpeg版) 
'作者:cuixiping 
'博客(CSDN):http://blog.csdn.net/cuixiping/ 
'博客(博客园):http://www.cnblogs.com/cuixiping/ 
'日期:2008年11月 
'生成100x20的jpeg图片验证码,内容类似“25+64等于?” 
'需要网站空间支持ASPJpeg组件(Persits.Jpeg)。 
'如果服务器没有“楷体_GB2312”字体,请修改为其他字体并调整字符位置。 
'使用方法:将该代码替换动网论坛的Dv_GetCode.asp文件中的内容,文件首尾不要留空行。 
'=============================================================================
 
Const FontColor = &H000000; ' 字体颜色 
Const BgColor = &HFFCCFF; ' 背景颜色 
 
Call CreatValidCode("GetCode") 
 
Sub CreatValidCode(pSN) 
Dim x, Jpeg 
Randomize 
x = Array(1+Int(Rnd()*9), Int(Rnd()*10), 1+Int(Rnd()*9), Int(Rnd()*10), 0, 0, "+") 
x(4) = x(0)*10 + x(1) 
x(5) = x(2)*10 + x(3) 
'Session(pSN) = CStr(Eval(x(4) & x(6) & x(5))) 
Session(pSN) = CStr(x(4) + x(5)) 
 
Set Jpeg = Server.CreateObject("Persits.Jpeg") 
Jpeg.New 100,20,BgColor 
Jpeg.Quality=100 
With Jpeg.Canvas 
.Font.Bold = True 
.Font.Size = 16 
.Font.Rotation = 0 
.Font.Family = "楷体_GB2312" 
.Font.Color = FontColor 
.PrintText 4, 3, CStr(x(0)) 
.PrintText 14, 3, CStr(x(1)) 
.PrintText 26, 3, x(6) 
.PrintText 38, 3, CStr(x(2)) 
.PrintText 48, 3, CStr(x(3)) 
.Font.Rotation = 15 
.PrintText 55, 3, "等" 
.PrintText 70, 3, "于" 
.PrintText 85, 3, "?" 
End With 
'禁止缓存 
Response.ContentType = "image/jpeg" 
Response.Expires = -9999 
Response.AddHeader "pragma", "no-cache" 
Response.AddHeader "cache-ctrol", "no-cache" 
Response.AddHeader "Content-Disposition","inline; filename=vcode.jpg" 
Jpeg.SendBinary 
Jpeg.Close 
Set Jpeg = Nothing 
End Sub 
%>