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

随心笔谈2个月前更新 admin
199 00
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

文章摘要

这篇文章主要介绍了如何使用VBScript语言在服务器端生成带有特定随机数和文本的图片,并通过HTTP响应发送这些图片。代码中通过随机函数生成数值,构造字符串并嵌入在图片中,最后设置响应头信息(如Content-Type、Expires、Content-Disposition等),确保图片在浏览器中正确显示。文章的核心内容是图片生成和发送的完整过程。


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

© 版权声明

相关文章