Verification code for php drawing application, php drawing Verification Code
In the plot, as we mentioned earlier, the plot of php is a real dynamic plot. Although I admit that the plot will look pretty bad, we should focus mainly on data processing.
Verification code is almost everywhere. Its generation and drawing technology are inseparable. In fact, it is very easy to draw a simple verification code, just like the following code, you can draw elements containing letters and numbers:
<? Php $ checkCode = ""; for ($ I = 0; $ I <= 3; $ I ++) {$ checkCode. = dechex (rand (110);} session_start (); $ _ SESSION ['checkcode'] = $ checkCode; // create a canvas $ img_1 = imagecreatetruecolor (, 30 ); $ red = imagecolorallocate ($ img_1, 255, 0, 0); imagestring ($ img_1, 5, 0, 0, $ checkCode, $ red); header ("Content-type: image/png "); imagepng ($ img_1); imagedestroy ($ img_1);?>
The above code is just a simple description of the verification code, in fact, the Code is not safe.
The following describes how to process the verification code:
<? Php $ checkCode = ""; for ($ I = 0; $ I <= 3; $ I ++) {$ checkCode. = dechex (rand ();} session_start (); $ _ SESSION ['checkcode'] = $ checkCode; // create a canvas $ img_1 = imagecreatetruecolor (70, 40 ); // you must first create a canvas and then create a color. $ Red = imagecolorallocate ($ img_1, rand (0,255), rand (0,255), rand (0,255); for ($ k = 0; $ k <= 20; $ k ++) {imageline ($ img_1, rand (0,255), rand (0,255), imagecolorallocate ($ img_1, rand (), rand ), rand (0,255);} imagestring ($ img_1, rand (), $ checkCode, $ red ); header ("Content-type: image/png"); imagepng ($ img_1); imagedestroy ($ img_1);?>