? Header ("Content-type:image/png"); Define header, declare picture file, preferably PNG, no copyright disturbance; To generate a new four-bit integer verification code Session_Start ()//open session; Authnum_session = '; str = ' abcdefghijkmnpqrstuvwxyz1234567890 '; Define the numbers and letters to be displayed on the picture; L = strlen (str); Gets the length of the string; The loop randomly extracts the four-bit previously defined letters and numbers; for (i=1;i<=4;i++) { Num=rand (0,L-1); Randomly extract one digit at a time, from the first word to the maximum length of the string, Minus 1 is because the Intercept character starts at 0, so that 34 characters may be in the line. Authnum_session.= Str[num]; will be through the number of words Fulianqi to a total of four bits; } Session_register ("Authnum_session"); Use the session to do verification is also good; Register session, name is Authnum_session, Other pages just include the picture That is, you can call it by _session["Authnum_session"] Generate a Captcha picture, Srand (Double) microtime () *1000000); im = Imagecreate (50,20);//Picture wide and high; Mainly used in black and white gray three kinds of color; Black = Imagecolorallocate (IM, 0,0,0); White = Imagecolorallocate (IM, 255,255,255); Gray = Imagecolorallocate (IM, 200,200,200); To draw a four-bit integer verification code into a picture Imagefill (Im,68,30,gray); If you do not need to disturb the line, comments on the line; Li = Imagecolorallocate (IM, 220,220,220); for (i=0;i<3;i++) {//Add 3 interference lines; it may not, depending on the circumstances, because it may affect user input; Imageline (Im,rand (0,30), Rand (0,21), Rand (20,40), Rand (0,21), Li); } character in the position of the picture; Imagestring (IM, 5, 8, 2, authnum_session, white); for (i=0;i<90;i++) {//Add interference pixels Imagesetpixel (IM, rand ()%70, Rand ()%30, Gray); } Imagepng (IM); Imagedestroy (IM); ?> |