PHP Verification Code making (Web Tree annotation idea) _php skills
Source: Internet
Author: User
1, generating random numbers
A For loop is used to determine how many random numbers are generated.
Random numbers are generated in the range of random functions. For example, Rand (1,15), generates a number from 1 to 15.
Use a 16-bit feed function to create a digital alphabet. Dechex (rand (1,15)).
Use the. = operation to hold several numbers.
Put the generated random number into the $_session[variable]. And so on in the future with the user submitted content comparison.
2, create a picture
Use the picture creation function to determine the size of the picture you created.
For example $im = Imagecreatetruecolor (100,30), where the coordinate 100,30 is the origin of the upper-left corner of the page, $im as a picture variable.
3, set the color Use functions to create a background color. For example $BG = Imagecolorallocate ($im, 0,0,0); 0,0,0 is a three-color number, $im for the picture created above
Use a function to create a font color. For example $te = Imagecolorallocate ($im, 255,255,255);
4, write the character in the upper-left corner of the image
Use the function imagestring () to write the character in the image. For example imagestring ($im, 5,0,0, $rand, $te); $im for the picture created above, 5 is the display way, 0,0
is the coordinates, $te is the font color
5, Output image Use the function header ("Content-type:image/jpeg"), imagejpeg ($im), and output the image.
----------------------------------I'm a gorgeous split line---------------------------
1, open session function, such as session_start ();
2, write the form
3, the verification code data submitted by the form is compared with the $_session[variable above
Equal, verified correctly.
is not equal, then an error.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service