1. use the for loop to generate random numbers. Use a random function to generate a random number within the specified range. For example, rand () generates numbers between 1 and 15. Use a hexadecimal function to create numbers and letters. Dechex (rand (1, 15 )). Use the. = operation to save several numbers. Place the generated random number to $ _ SESSION [variable]. "> <LINKhref
1. Generate a random number
Use the for loop to generate several random numbers.
Use a random function to generate a random number within the specified range. For example, rand () generates numbers between 1 and 15.
Use a hexadecimal function to create numbers and letters. Dechex (rand (1, 15 )).
Use the. = operation to save several numbers.
Place the generated random number to $ _ SESSION [variable]. .
2. create an image
Use the image creation function to determine the size of the created image.
For example, $ im = imagecreatetruecolor (, 30); the coordinates, 30 are the origin point in the upper left corner of the page, and $ im is the image variable.
3. set the color.
Use the function to create a background color. For example, $ bg = imagecolorallocate ($ im, 0); where 0, 0 is the primary color number, $ im is the image created above
Use the function to create a font color. For example, $ te = imagecolorallocate ($ im, 255,255,255 );
4. write the characters in the upper left corner of the image.
Use the imagestring () function to write the character in the image. For example, imagestring ($ im, 5, 0, 0, $ rand, $ te); $ im is the image created above, 5 is the display mode, 0, 0
Is the coordinate, $ te is the font color
5. output image
Use the function header ("Content-type: image/jpeg"); imagejpeg ($ im); to output the image.
---------------------------------- I am a gorgeous split line ---------------------------
1. enable the session function. for example, session_start ();
2. write a form
3. compare the verification code data submitted by the form with the above $ _ SESSION [variable]
Equal. the verification is correct.
Otherwise, an error occurs.