网站启动SSL, http变为https后,session验证码错误解决方法
最近公司需要后台启动安全证书,证书安装完毕后,后台老提示 验证码错误,经过几天的研究,此问题已经得到有效解决,现把方法如下。
一、问题展示
看到此问题后,我求助了伟大的互联网,网上大概的解决方法,是说要写两个session,不能相互互通,按照这个思路,我整了几天不见好,后来我重新写了一段代码,问题解决,其实根本不需要写两个session,先公布解决方法。
二、解决方法
原来的验证码代码
<script language="vbscript" runat="server">Option Explicit '显示声明Dim showErrorImgshowErrorImg = Falsefunction ChkPost() dim server_v1,server_v2chkpost=falseserver_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))If Mid(server_v1,8,Len(server_v2))<>server_v2 thenchkpost=Falseelsechkpost=Trueend Ifend FunctionIf Not ChkPost() ThenshowErrorImg = trueEnd IfClass Com_GifCode_ClassPublic Noisy, Count, Width, Height, Angle, Offset, BorderPrivate Graph(), Margin(3)Private Sub Class_Initialize()Randomize Noisy = 1 ' 干扰点出现的概率 Count = 4 ' 字符数量 Width = 40 ' 图片宽度 Height = 20 ' 图片高度 Angle = 2 ' 角度随机变化量 Offset = 15 ' 偏移随机变化量 Border = 1.5 ' 边框大小End Sub Public Function Create2(str)Dim iDim vIndexReDim Graph(Width-1, Height-1)For i = 0 To Count - 1vIndex=CInt(Mid(str,i+1,1)-1)SetDraw vIndex, iNextEnd FunctionSub SetDot(pX, pY)If pX * (Width-pX-1) >= 0 And pY * (Height-pY-1) >= 0 ThenGraph(pX, pY) = 1End IfEnd SubPublic Sub SetDraw(pIndex, pNumber)' 字符数据字典If pIndex=-1 Then pIndex=9Dim DotData(9)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) DotData(9) = Array(100, 20, 70, 1, 20, 1, 1, 30, 1, 80, 30, 100, 70, 100, 100, 80, 100, 60, 90, 20, 80,3)Dim vExtent : vExtent = Width / CountMargin(0) = Border + vExtent * (Rnd * Offset) / 100 + Margin(1)Margin(1) = vExtent * (pNumber + 1) - Border - vExtent * (Rnd * Offset) / 100Margin(2) = Border + Height * (Rnd * Offset) / 100Margin(3) = Height - Border - Height * (Rnd * Offset) / 100Dim vStartX, vEndX, vStartY, vEndYDim vWidth, vHeight, vDX, vDY, vDeltaTDim vAngle, vLengthvWidth =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, jFor i = 1 To UBound(DotData(pIndex), 1)/2If DotData(pIndex)(2*i-2) <> 0 And DotData(pIndex)(2*i) <> 0 Then vEndX = (DotData(pIndex)(2*i)-1) * vWidth / 100vEndY = (DotData(pIndex)(2*i+1)-1) * vHeight / 100vDX = vEndX - vStartXvDY = vEndY - vStartYIf vDX = 0 ThenvAngle = Sgn(vDY) * 3.14 /2ElsevAngle = Atn(vDY / vDX)End IfIf Sin(vAngle) = 0 ThenvLength = vDXElsevLength = vDY / Sin(vAngle)End IfvAngle = vAngle + (Rnd - 0.5) * 2 * Angle * 3.14 * 2 / 100vDX = 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 vDeltaTSetDot Margin(0) + vStartX + j * vDX / vDeltaT, Margin(2) + vStartY + j * vDY / vDeltaT NextvStartX = vStartX + vDXvStartY = vStartY + vDYEnd IfNextEnd SubPublic Sub Output()Response.Expires = -9999Response.AddHeader "pragma", "no-cache"Response.AddHeader "cache-ctrol", "no-cache"Response.ContentType = "image/gif" Response.BinaryWrite ChrB(Asc("G")) & ChrB(Asc("I")) & ChrB(Asc("F"))Response.BinaryWrite ChrB(Asc("8")) & ChrB(Asc("9")) & ChrB(Asc("a")) Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)Response.BinaryWrite ChrB(128) & ChrB(0) & ChrB(0) Response.BinaryWrite ChrB(250) & ChrB(250) & ChrB(250)Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0)Response.BinaryWrite ChrB(Asc(","))Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) Response.BinaryWrite ChrB(Width Mod 256) & ChrB((Width \ 256) Mod 256)Response.BinaryWrite ChrB(Height Mod 256) & ChrB((Height \ 256) Mod 256)Response.BinaryWrite ChrB(0) & ChrB(7) & ChrB(255) Dim x, y, i : i = 0For y = 0 To Height - 1For x = 0 To Width - 1If Rnd < Noisy / 100 ThenResponse.BinaryWrite ChrB(1-Graph(x, y))ElseIf x * (x-Width) = 0 Or y * (y-Height) = 0 Then Response.BinaryWrite ChrB(Graph(x, y))ElseIf Graph(x-1, y) = 1 Or Graph(x, y) Or Graph(x, y-1) = 1 ThenResponse.BinaryWrite ChrB(1)ElseResponse.BinaryWrite ChrB(0)End IfIf (y * Width + x + 1) Mod 126 = 0 ThenResponse.BinaryWrite ChrB(128)i = i + 1End IfIf (y * Width + x + i + 1) Mod 255 = 0 ThenIf (Width*Height - y * Width - x - 1) > 255 Then Response.BinaryWrite ChrB(255)ElseResponse.BinaryWrite ChrB(Width * Height Mod 255)End IfEnd IfNextNextResponse.BinaryWrite ChrB(128) & ChrB(0) & ChrB(129) & ChrB(0) & ChrB(59) End SubEnd Class''''''''''''''''''''''''''''''''''''''''''''''''''''''Dim mCodeSet mCode = New Com_GifCode_ClassRandomizeDim codecode = Int(Rnd * 9000 + 1000)If showErrorImg ThenSession("GetCode") = Int(Rnd * 9000 + 1000)elseSession("GetCode") = codeEnd IfmCode.Create2(code)mCode.Output()</script>
重写之后的代码
<% Const nMaxSaturation = 100 ' 最大色彩饱和度 Const nBlankNoisyDotOdds = 0.2 ' 空白处噪点率 Const nColorNoisyDotOdds = 0 ' 有色处噪点率 Const nCharCount = 5 ' 产生的字符个数 Const nPixelWidth = 20 ' 单个字符位图的宽度 Const nPixelHeight = 20 ' 单个字符位图的高度 Const nColorHue = 000 ' 显示验证码的色调(-1表示随机色调, -2表示灰度色调) Const nAngleRandom = 10 ' 角度随机量 Const nLengthRandom = 10 ' 长度随机量(百分比) Const cCharSet = "0123456789"' 构成验证码的字符集' 如果扩充了下边的字母矢量库,则可以相应扩充这个字符集Dim Buf(), DigtalStr Dim Lines(), LineCount Dim CursorX, CursorY, DirX, DirYRandomize Call CreatValidCode("GetCode")Sub CDGen_Reset()' 复位矢量笔和环境变量LineCount = 0CursorX = 0CursorY = 0' 初始的光笔方向是垂直向下DirX = 0DirY = 1 End SubSub CDGen_Clear()' 清空位图阵列Dim i, jReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)For j = 0 To nPixelHeight - 1For i = 0 To nCharCount * nPixelWidth - 1Buf(j, i) = 0NextNext End SubSub CDGen_PSet(X, Y)' 在位图阵列上画点Buf(Y, X) = 1 End SubSub CDGen_Line(X1, Y1, X2, Y2)' 在位图阵列上画线Dim DX, DY, DeltaT, iDX = X2 - X1DY = Y2 - Y1If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)For i = 0 To DeltaTCDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaTNext End SubSub CDGen_FowardDraw(nLength)' 按当前光笔方向绘制指定长度并移动光笔,正数表示从左向右/从上向下绘制,负数表示从右向左/从下向上绘制nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLenghtRandom * 2 / 100)ReDim Preserve Lines(3, LineCount)Lines(0, LineCount) = CursorXLines(1, LineCount) = CursorYCursorX = CursorX + DirX * nLengthCursorY = CursorY + DirY * nLengthLines(2, LineCount) = CursorXLines(3, LineCount) = CursorYLineCount = LineCount + 1 End SubSub CDGen_SetDirection(nAngle)' 按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向,负数表示相对当前方向逆时针改变方向Dim DX, DYnAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926DX = DirXDY = DirYDirX = DX * Cos(nAngle) - DY * Sin(nAngle)DirY = DX * Sin(nAngle) + DY * Cos(nAngle) End SubSub CDGen_MoveToMiddle(nActionIndex, nPercent)' 将画笔光标移动到指定动作的中间点上,nPercent为中间位置的百分比Dim DeltaX, DeltaYDeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100 End SubSub CDGen_MoveCursor(nActionIndex)' 将画笔光标移动到指定动作的起始点上CursorX = Lines(0, nActionIndex)CursorY = Lines(1, nActionIndex) End SubSub CDGen_Close(nActionIndex)' 将当前光笔位置与指定动作的起始点闭合并移动光笔ReDim Preserve Lines(3, LineCount)Lines(0, LineCount) = CursorXLines(1, LineCount) = CursorYCursorX = Lines(0, nActionIndex)CursorY = Lines(1, nActionIndex)Lines(2, LineCount) = CursorXLines(3, LineCount) = CursorYLineCount = LineCount + 1 End SubSub CDGen_CloseToMiddle(nActionIndex, nPercent)' 将当前光笔位置与指定动作的中间点闭合并移动光笔,nPercent为中间位置的百分比Dim DeltaX, DeltaYReDim Preserve Lines(3, LineCount)Lines(0, LineCount) = CursorXLines(1, LineCount) = CursorYDeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100Lines(2, LineCount) = CursorXLines(3, LineCount) = CursorYLineCount = LineCount + 1 End SubSub CDGen_Flush(X0, Y0)' 按照当前的画笔动作序列绘制位图点阵Dim MaxX, MinX, MaxY, MinYDim DeltaX, DeltaY, StepX, StepY, OffsetX, OffsetYDim iMaxX = MinX = MaxY = MinY = 0For i = 0 To LineCount - 1If MaxX < Lines(0, i) Then MaxX = Lines(0, i)If MaxX < Lines(2, i) Then MaxX = Lines(2, i)If MinX > Lines(0, i) Then MinX = Lines(0, i)If MinX > Lines(2, i) Then MinX = Lines(2, i)If MaxY < Lines(1, i) Then MaxY = Lines(1, i)If MaxY < Lines(3, i) Then MaxY = Lines(3, i)If MinY > Lines(1, i) Then MinY = Lines(1, i)If MinY > Lines(3, i) Then MinY = Lines(3, i)NextDeltaX = MaxX - MinXDeltaY = MaxY - MinYIf DeltaX = 0 Then DeltaX = 1If DeltaY = 0 Then DeltaY = 1MaxX = MinXMaxY = MinYIf DeltaX > DeltaY ThenStepX = (nPixelWidth - 2) / DeltaXStepY = (nPixelHeight - 2) / DeltaXOffsetX = 0OffsetY = (DeltaX - DeltaY) / 2ElseStepX = (nPixelWidth - 2) / DeltaYStepY = (nPixelHeight - 2) / DeltaYOffsetX = (DeltaY - DeltaX) / 2OffsetY = 0End IfFor i = 0 To LineCount - 1Lines(0, i) = Round((Lines(0, i) - MaxX + OffsetX) * StepX, 0)If Lines(0, i) < 0 Then Lines(0, i) = 0If Lines(0, i) >= nPixelWidth - 2 Then Lines(0, i) = nPixelWidth - 3Lines(1, i) = Round((Lines(1, i) - MaxY + OffsetY) * StepY, 0)If Lines(1, i) < 0 Then Lines(1, i) = 0If Lines(1, i) >= nPixelHeight - 2 Then Lines(1, i) = nPixelHeight - 3Lines(2, i) = Round((Lines(2, i) - MinX + OffsetX) * StepX, 0)If Lines(2, i) < 0 Then Lines(2, i) = 0If Lines(2, i) >= nPixelWidth - 2 Then Lines(2, i) = nPixelWidth - 3Lines(3, i) = Round((Lines(3, i) - MinY + OffsetY) * StepY, 0)If Lines(3, i) < 0 Then Lines(3, i) = 0If Lines(3, i) >= nPixelHeight - 2 Then Lines(3, i) = nPixelHeight - 3CDGen_Line Lines(0, i) + X0 + 1, Lines(1, i) + Y0 + 1, Lines(2, i) + X0 + 1, Lines(3, i) + Y0 + 1Next End SubSub CDGen_Char(cChar, X0, Y0)' 在指定坐标处生成指定字符的位图阵列 CDGen_ResetSelect Case cCharCase "0"CDGen_SetDirection -60 ' 逆时针60度(相对于垂直线)CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 逆时针60度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 1.5 ' 绘制1.5个单位CDGen_SetDirection -60 ' 逆时针60度CDGen_FowardDraw 0.7 ' 绘制0.7个单位CDGen_SetDirection -60 ' 顺时针120度CDGen_FowardDraw 0.7 ' 绘制0.7个单位CDGen_Close 0 ' 封闭当前笔与第0笔(0开始)Case "1"CDGen_SetDirection -90 ' 逆时针90度(相对于垂直线)CDGen_FowardDraw 0.5 ' 绘制0.5个单位CDGen_MoveToMiddle 0, 50 ' 移动画笔的位置到第0笔(0开始)的50%处CDGen_SetDirection 90 ' 逆时针90度CDGen_FowardDraw -1.4 ' 反方向绘制1.4个单位CDGen_SetDirection 30 ' 逆时针30度CDGen_FowardDraw 0.4 ' 绘制0.4个单位Case "2"CDGen_SetDirection 45 ' 顺时针45度(相对于垂直线)CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -120 ' 逆时针120度CDGen_FowardDraw 0.4 ' 绘制0.4个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.6 ' 绘制0.6个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 1.6 ' 绘制1.6个单位CDGen_SetDirection -135 ' 逆时针135度CDGen_FowardDraw 1.0 ' 绘制1.0个单位Case "3"CDGen_SetDirection -90 ' 逆时针90度(相对于垂直线)CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection 135 ' 顺时针135度CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection -120 ' 逆时针120度CDGen_FowardDraw 0.6 ' 绘制0.6个单位CDGen_SetDirection 80 ' 顺时针80度CDGen_FowardDraw 0.5 ' 绘制0.5个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.5 ' 绘制0.5个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.5 ' 绘制0.5个单位Case "4"CDGen_SetDirection 20 ' 顺时针20度(相对于垂直线)CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection -110 ' 逆时针110度CDGen_FowardDraw 1.2 ' 绘制1.2个单位CDGen_MoveToMiddle 1, 60 ' 移动画笔的位置到第1笔(0开始)的60%处CDGen_SetDirection 90 ' 顺时针90度CDGen_FowardDraw 0.7 ' 绘制0.7个单位CDGen_MoveCursor 2 ' 移动画笔到第2笔(0开始)的开始处CDGen_FowardDraw -1.5 ' 反方向绘制1.5个单位Case "5"CDGen_SetDirection 90 ' 顺时针90度(相对于垂直线)CDGen_FowardDraw 1.0 ' 绘制1.0个单位CDGen_SetDirection -90 ' 逆时针90度CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection -90 ' 逆时针90度CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection 30 ' 顺时针30度CDGen_FowardDraw 0.4 ' 绘制0.4个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.4 ' 绘制0.4个单位CDGen_SetDirection 30 ' 顺时针30度CDGen_FowardDraw 0.5 ' 绘制0.5个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.8 ' 绘制0.8个单位Case "6"CDGen_SetDirection -60 ' 逆时针60度(相对于垂直线)CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 逆时针60度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 1.5 ' 绘制1.5个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 0.7 ' 绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 0.5 ' 绘制0.5个单位CDGen_CloseToMiddle 2, 50 ' 将当前画笔位置与第2笔(0开始)的50%处封闭Case "7"CDGen_SetDirection 180 ' 顺时针180度(相对于垂直线)CDGen_FowardDraw 0.3 ' 绘制0.3个单位CDGen_SetDirection 90 ' 顺时针90度CDGen_FowardDraw 0.9 ' 绘制0.9个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 1.3 ' 绘制1.3个单位Case "8"CDGen_SetDirection -60 ' 逆时针60度(相对于垂直线)CDGen_FowardDraw -0.8 ' 反方向绘制0.8个单位CDGen_SetDirection -60 ' 逆时针60度CDGen_FowardDraw -0.8 ' 反方向绘制0.8个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection 110 ' 顺时针110度CDGen_FowardDraw -1.5 ' 反方向绘制1.5个单位CDGen_SetDirection -110 ' 逆时针110度CDGen_FowardDraw 0.9 ' 绘制0.9个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.8 ' 绘制0.8个单位CDGen_SetDirection 60 ' 顺时针60度CDGen_FowardDraw 0.9 ' 绘制0.9个单位CDGen_SetDirection 70 ' 顺时针70度CDGen_FowardDraw 1.5 ' 绘制1.5个单位CDGen_Close 0 ' 封闭当前笔与第0笔(0开始)Case "9"CDGen_SetDirection 120 ' 逆时针60度(相对于垂直线)CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 逆时针60度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 顺时针120度CDGen_FowardDraw -1.5 ' 绘制1.5个单位CDGen_SetDirection -60 ' 顺时针120度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 顺时针120度CDGen_FowardDraw -0.7 ' 绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 顺时针120度CDGen_FowardDraw 0.5 ' 绘制0.5个单位CDGen_CloseToMiddle 2, 50 ' 将当前画笔位置与第2笔(0开始)的50%处封闭' 以下为字母的矢量动作,有兴趣的可以继续Case "A"CDGen_SetDirection -(Rnd * 20 + 150) ' 逆时针150-170度(相对于垂直线)CDGen_FowardDraw Rnd * 0.2 + 1.1 ' 绘制1.1-1.3个单位CDGen_SetDirection Rnd * 20 + 140 ' 顺时针140-160度CDGen_FowardDraw Rnd * 0.2 + 1.1 ' 绘制1.1-1.3个单位CDGen_MoveToMiddle 0, 30 ' 移动画笔的位置到第1笔(0开始)的30%处CDGen_CloseToMiddle 1, 70 ' 将当前画笔位置与第1笔(0开始)的70%处封闭Case "B"CDGen_SetDirection -(Rnd * 20 + 50) ' 逆时针50-70度(相对于垂直线)CDGen_FowardDraw Rnd * 0.4 + 0.8 ' 绘制0.8-1.2个单位CDGen_SetDirection Rnd * 20 + 110 ' 顺时针110-130度CDGen_FowardDraw Rnd * 0.2 + 0.6 ' 绘制0.6-0.8个单位CDGen_SetDirection -(Rnd * 20 + 110) ' 逆时针110-130度CDGen_FowardDraw Rnd * 0.2 + 0.6 ' 绘制0.6-0.8个单位CDGen_SetDirection Rnd * 20 + 110 ' 顺时针110-130度CDGen_FowardDraw Rnd * 0.4 + 0.8 ' 绘制0.8-1.2个单位CDGen_Close 0 ' 封闭当前笔与第1笔(0开始)Case "C"CDGen_SetDirection -60 ' 逆时针60度(相对于垂直线)CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection -60 ' 逆时针60度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 1.5 ' 绘制1.5个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw -0.7 ' 反方向绘制0.7个单位CDGen_SetDirection 120 ' 顺时针120度CDGen_FowardDraw 0.7 ' 绘制0.7个单位End SelectCDGen_Flush X0, Y0 End SubSub CDGen_Blur()' 对产生的位图进行柔化处理Dim i, jFor j = 1 To nPixelHeight - 2For i = 1 To nCharCount * nPixelWidth - 2If Buf(j, i) = 0 ThenIf ((Buf(j, i - 1) Or Buf(j + 1, i)) And 1) <> 0 Then' 如果当前点是空白点,且上下左右四个点中有一个点是有色点,则该点做柔化处理Buf(j, i) = 2End IfEnd IfNextNext End SubSub CDGen_NoisyDot()' 对产生的位图进行噪点处理Dim i, j, NoisyDot, CurDotFor j = 0 To nPixelHeight - 1For i = 0 To nCharCount * nPixelWidth - 1If Buf(j, i) <> 0 ThenNoisyDot = Int(Rnd * Rnd * nMaxSaturation)Select Case nColorNoisyDotOddsCase 0CurDot = nMaxSaturationCase 1CurDot = 0Case ElseCurDot = NoisyDotEnd SelectIf Rnd < nColorNoisyDotOdds Then Buf(j, i) = CurDot Else Buf(j, i) = nMaxSaturationElseNoisyDot = Int(Rnd * nMaxSaturation)Select Case nBlankNoisyDotOddsCase 0CurDot = 0Case 1CurDot = nMaxSaturationCase ElseCurDot = NoisyDotEnd SelectIf Rnd < nBlankNoisyDotOdds Then Buf(j, i) = CurDot Else Buf(j, i) = 0End IfNextNext End SubSub CDGen()' 生成位图阵列Dim i, ChDigtalStr = ""CDGen_ClearFor i = 0 To nCharCount - 1Ch = Mid(cCharSet, Int(Rnd * Len(cCharSet)) + 1, 1)DigtalStr = DigtalStr + ChCDGen_Char Ch, i * nPixelWidth, 0NextCDGen_BlurCDGen_NoisyDot End SubFunction HSBToRGB(vH, vS, vB)' 将颜色值由HSB转换为RGBDim aRGB(3), RGB1st, RGB2nd, RGB3rdDim nH, nS, nBDim lH, nF, nP, nQ, nTvH = (vH Mod 360)If vS > 100 ThenvS = 100ElseIf vS < 0 ThenvS = 0End IfIf vB > 100 ThenvB = 100ElseIf vB < 0 ThenvB = 0End IfIf vS > 0 ThennH = vH / 60nS = vS / 100nB = vB / 100lH = Int(nH)nF = nH - lHnP = nB * (1 - nS)nQ = nB * (1 - nS * nF)nT = nB * (1 - nS * (1 - nF))Select Case lHCase 0aRGB(0) = nB * 255aRGB(1) = nT * 255aRGB(2) = nP * 255Case 1aRGB(0) = nQ * 255aRGB(1) = nB * 255aRGB(2) = nP * 255Case 2aRGB(0) = nP * 255aRGB(1) = nB * 255 aRGB(2) = nT * 255Case 3aRGB(0) = nP * 255aRGB(1) = nQ * 255aRGB(2) = nB * 255Case 4aRGB(0) = nT * 255aRGB(1) = nP * 255aRGB(2) = nB * 255Case 5aRGB(0) = nB * 255aRGB(1) = nP * 255aRGB(2) = nQ * 255End Select ElseaRGB(0) = (vB * 255) / 100aRGB(1) = aRGB(0)aRGB(2) = aRGB(0)End IfHSBToRGB = ChrB(Round(aRGB(2), 0)) & ChrB(Round(aRGB(1), 0)) & ChrB(Round(aRGB(0), 0)) End FunctionSub CreatValidCode(pSN)Dim i, j, CurColorHue' 禁止缓存Response.Expires = -9999Response.AddHeader "pragma", "no-cache"Response.AddHeader "cache-ctrol", "no-cache"Response.ContentType = "image/bmp"Call CDGenSession(pSN) = DigtalStr '记录入SessionDim PicWidth, PicHeight, FileSize, PicDataSizePicWidth = nCharCount * nPixelWidthPicHeight = nPixelHeightPicDataSize = PicWidth * PicHeight * 3FileSize = PicDataSize + 54' 输出BMP文件信息头Response.BinaryWrite ChrB(66) & ChrB(77) & _ChrB(FileSize Mod 256) & ChrB((FileSize \ 256) Mod 256) & ChrB((FileSize \ 256 \ 256) Mod 256) & ChrB(FileSize \ 256 \ 256 \ 256) & _ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & _ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0)' 输出BMP位图信息头Response.BinaryWrite ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & _ChrB(PicWidth Mod 256) & ChrB((PicWidth \ 256) Mod 256) & ChrB((PicWidth \ 256 \ 256) Mod 256) & ChrB(PicWidth \ 256 \ 256 \ 256) & _ChrB(PicHeight Mod 256) & ChrB((PicHeight \ 256) Mod 256) & ChrB((PicHeight \ 256 \ 256) Mod 256) & ChrB(PicHeight \ 256 \ 256 \ 256) & _ChrB(1) & ChrB(0) & _ChrB(24) & ChrB(0) & _ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & _ChrB(PicDataSize Mod 256) & ChrB((PicDataSize \ 256) Mod 256) & ChrB((PicDataSize \ 256 \ 256) Mod 256) & ChrB(PicDataSize \ 256 \ 256 \ 256) & _ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & _ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & _ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & _ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)' 逐点输出位图阵列If nColorHue = -1 ThenCurColorHue = Int(Rnd * 360)ElseIf nColorHue = -2 ThenCurColorHue = 0ElseCurColorHue = nColorHueEnd IfFor j = 0 To nPixelHeight - 1For i = 0 To Len(DigtalStr) * nPixelWidth - 1If nColorHue = -2 ThenResponse.BinaryWrite HSBToRGB(CurColorHue, 0, 100 - Buf(nPixelHeight - 1 - j, i))ElseResponse.BinaryWrite HSBToRGB(CurColorHue, Buf(nPixelHeight - 1 - j, i), 100)End IfNextNext End Sub %>
问题解决。