Digital and alphanumeric combines and generate pictures verification code Xiang solution

zhaozj2021-02-16  56

Everyone often sees the verification code when they log in online, some are text, some are pictures, such as the message in chinaren.com, we will see the digital image verification code; online about The digital text verification code implementation method is much related, and we introduce the implementation of the digital and letters, and generate the verification code of the image. It looks very complicated, in fact, it is very simple, everyone follows me to see: First, let's introduce the design idea, numbers, and letters of random combination generation verification code, then generate pictures, here "" numbers and letters "It should be randomly taken; if it is a special digital verification code, we can implement: Ycodenum = 4 'verification code number, or a number for i = 1 to Ycodenum Randomize' initialization random number generator Ycode = Ycode & int ((9 * RND)) 'RND is random number, from 0 to 1, any real number, here the integer NEXT RESPONSE.WRITE YCODE' can output digital verification code (4 digits) However, we must let the numbers and letters are also randomly generated. Here we can use an array to achieve this effect, as follows: Ychar = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a , B, C, D, E, F, G, H, I, P, Q, R, S, T, U, V, W, X, Y, Z "'Make numbers and uppercase letters into a string yc = split (char,", ")' to generate a string to generate array ycodenum = 4 for i = 1 to ycoDenum randomize ycode = Ycode & Yc (INT))) The array is generally read from 0, so here is 35 * RND next response.write Ycode now look at the output result is the number and letters random combination? Let's take a look at how to generate pictures, this may have some friends know: ASP can't generate pictures, you must use the ASP component. Yes, we use the ASP image component Shotgraph here. One point, pay attention, the server is not your own, because you can't install this component.

Component's download address: http://www.wrclub.net/down.aspx? Id = 545, as for how to register, there are not many words here, there are many information on the Internet. Let's take a look at the code for generating pictures: Ychar = "0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p , Q, R, S, T, U, V, W, X, Y, Z "set the numbers and uppercase letters into a string yc = split (char,", ") 'to generate a string to generate array YcoDenum = 4 For i = 1 to Ycodenum Randomize Ycode = Ycode & YC (INT)) 'The array is generally read from 0, so here is 35 * RND NEXT RESPONSE.CLAR RESPONSE.CONTENTTYPE = "image / gif" set obj = Server.createObject ("shotgraph.image") x = 55 'Picture of the width Y = 26' picture of the high obj.createImage X, Y, 8 '8 is the color 8 Obj.SetColor 0,55,126,222 Obj.setColor 1,255,255,255 obj.createpen "ps_solid", 1, 0 obj.setbgcolor 0 obj.Rectangle 0, 0, X-1, Y-1 Obj.SetBkmode "Transparent" Obj.createFont "Arial", 136, 18, 1, false, False, False, False Obj.SettextColor 1 Obj.Textout 5, 4, Ycode & "IMG = Obj.gifimage (-1, 1,") Response.binaryWrite (IMG) is the above code is also a map of Shotgraph's ordinary picture Principle, please refer to: http://www.pconline.com.cn/pcedu/empolder/wz/asp/10204/45207.html ok, this is done, let's take a look! Explanation, the above generated picture components and code are provided by poison love, what suggestions or better methods can be posted to the Net Forum (http://bbs.wrclub.net), the Nets Forum always welcomes you. ! Original source: http://www.wrclub.net/show.aspx? Id = 1524

转载请注明原文地址:https://www.9cbs.com/read-22794.html

New Post(0)