1, generate random number
Use a for loop to determine how many random numbers are generated.
Use a random function to generate random numbers within a range. For example, rand(1,15) generates a number between 1 and 15.
Use the 16-bit base function to alphabetize the generated number. dechex(rand(1,15)).
Use the .= operator to save several numbers.
Put the generated random number into $_SESSION[variable]. Compare with user-submitted content in the future.
2. Create pictures
Use the image creation function to determine the size of the created image.
For example, $im = imagecreatetruecolor(100,30); where the coordinates 100 and 30 are based on the upper left corner of the web page as the origin, and $im is the image variable.
3. Set color
Use the function to create a background color. For example $bg = imagecolorallocate($im,0,0,0); where 0,0,0 are the three primary color numbers, $im is the picture 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 function imagestring() to write characters 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 the gorgeous dividing line---------- ------------------
1. Turn on the session function; for example session_start();
2. Write a form
3. Compare the verification code data submitted by the form with the $_SESSION [variable] above
Equal, the verification is correct.
If not equal, it is an error.