Php verification code production ideas and implementation methods, php verification code production ideas. Php verification code production ideas and implementation methods, php verification code production ideas 1. production ideas because the registration code is often used during registration to prevent malicious machine registration, here I will describe how to create a php verification code and how to implement it.
I. production ideas
Because the registration code is often used during registration to prevent malicious machine registration, here I am posting a basic image that generates a png image verification code, a simple analysis of the ideas:
1. generate a png image
2. set the background color for the image
3. set the font color and style
4. generate a 4-digit random verification code
5. adjust the rotation angle and position of each generated character to the png image.
6. add noise and interference lines to prevent registration machines from malicious registration by analyzing original images
7. output image
8. release memory occupied by images
II. implementation method
Authcode. php file
<? Php session_start (); header ('content-type: image/png '); // create an image $ im = imagecreate ($ x = 130, $ y = 45 ); $ bg = imagecolorallocate ($ im, rand (50,200), rand (0,155), rand (0,155); // The first time on imagecolorallocate () the call will fill the background color $ fontColor = imageColorAllocate ($ im, 255,255,255) for the color palette-based image; // fontstyle = 'rock. ttf'; // the font style, which can be found in the c: \ windows \ Fonts \ folder. I put it in the and authcode. the PHP file is in the same directory. you can replace other font styles here // Generate random characters for ($ I = 0; $ I <4; $ I ++) {$ randAsciiNumArray = array (rand (48, 57), rand (65,90); $ randAsciiNum = $ randAsciiNumArray [rand (0, 1)]; $ randStr = chr ($ randAsciiNum); imagettftext ($ im, 30, rand ()-rand (), 5 + $ I * 30, rand (30,35), $ fontColor, $ fontstyle, $ randStr); $ authcode. = $ randStr;} $ _ SESSION ['authcode'] = $ randFourStr; // compare the verification code entered by the user with that entered by the user // interfere with the line for ($ I = 0; $ I <8; $ I ++) {$ lineColor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); imageline ($ im, rand (0, $ x), 0, rand (0, $ x), $ y, $ lineColor) ;}// interference point for ($ I = 0; $ I <250; $ I ++) {imagesetpixel ($ im, rand (0, $ x ), rand (0, $ y), $ fontColor);} imagepng ($ im); imagedestroy ($ im);?>
:
The above is the php verification code production idea and implementation method, hope to help you learn.
Idea 1. production idea because the registration code is often used during registration to prevent malicious machine registration. here I will describe one...