ASP实现加法验证码(asp中的加法运算)学会了吗

随心笔谈2年前发布 admin
200 0 0

文章摘要

这篇文章介绍了如何使用VBScript编写一个生成图片文字验证码的脚本。文章详细描述了代码的各个部分,包括定义颜色常量、生成随机数据、创建和绘制验证码图片,以及设置图片属性以防止缓存。核心内容是通过脚本实现图片验证码的自动生成和显示,确保验证码在浏览器中无法被缓存。文章中还提到了使用Session和Jpeg对象的操作,以及如何通过设置Content-Type和Header属性来实现防缓存功能。


<%
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
%>

© 版权声明

相关文章