网页注册验证码怎么生成和如何刷新啊??
------解决方案--------------------
生成用服务端语言,比如以下是我用asp.net/vb写的
- VB.NET code
Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Partial Class getpassimgcode Inherits System.Web.UI.Page Dim rand As New Random() Dim r As Byte, g As Byte, b As Byte Dim imagebackgroundbrightness As Byte = 162 Function gethightcontrastcolor(Optional ByVal brightness1 As Byte = 255, Optional ByVal dif As Byte = 60) As Color r = rand.Next(0, 256) g = rand.Next(0, 256) b = rand.Next(0, 256) While Math.Abs(getcolorbrightness(r, g, b) - brightness1) < dif r = rand.Next(0, 256) g = rand.Next(0, 256) b = rand.Next(0, 256) End While Return Color.FromArgb(r, g, b) End Function Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim VNum As String = Right(Rnd().ToString, 5) Session("VNum") = VNum If Not Request.UrlReferrer Is Nothing AndAlso Request.UrlReferrer.ToString.IndexOf("userlogin.aspx") > -1 Then imagebackgroundbrightness = 255 ValidateCode(VNum) End Sub '生成图象验证码函数 Sub ValidateCode(ByVal VNum As String) Dim Img As System.Drawing.Bitmap Dim g As Graphics Dim ms As MemoryStream Dim gheight As Integer = Int(Len(VNum) * 11.5) 'gheight为图片宽度,根据字符长度自动更改图片宽度 Img = New Bitmap(gheight, 20) g = Graphics.FromImage(Img) For i As Int16 = 1 To Len(VNum) g.DrawString(Mid(VNum, i, 1), New Font("Arial", 10, FontStyle.Bold), New SolidBrush(gethightcontrastcolor(imagebackgroundbrightness)), (i - 1) * 10 + 3, 3) Next ms = New MemoryStream() Img.Save(ms, ImageFormat.Png) Response.ClearContent() '需要输出图象信息 要修改HTTP头 Response.ContentType = "image/Png" Response.BinaryWrite(ms.ToArray()) g.Dispose() Img.Dispose() Response.End() End Sub Function getcolorbrightness(ByVal r As Int16, ByVal g As Int16, ByVal b As Int16) As Double Return (299 * r + 587 * g + 114 * b) / 1000 End Function End Class
------解决方案--------------------