|
<? Php
For ($ I = 0; $ I <5; $ I ++ ){
$ Suijishu. = dechex (rand (); // use a loop to generate a five-digit hexadecimal format
}
Setcookie ("useryzm", $ suijishu); // Create a cookie named useryzm with the value of $ suijishu
$ Img = imagecreatetruecolor (100, 30); // create an image verification code with a width of and a height of 30.
$ Bg = imagecolorallocate ($ img, rand (0,255), rand (0,255), rand (0,255); // defines the background color of the verification code.
$ SC = imagecolorallocate ($ img, rand (0,255), rand (0,255), rand (0,255); // defines the font color of the verification code.
Imagestring ($ img, 5, rand (), rand (), $ suijishu, $ SC); // defines the font position (the coordinate origin in the upper left corner)
For ($ k = 0; $ k <10; $ k ++ ){
Imageline ($ img, rand (1,100), rand (1,100), rand (1,100), rand (1,100), $ SC); // draw a straight line on the verification code (disturbing)
Imagesetpixel ($ img, rand (1,100), rand (), $ SC); // draw points on the verification code (disturbing)
}
Ob_clean (); // clear the output buffer (This sentence is very important)
Header ("Content-type: image/jpeg"); // defines the format of the output image (image/can be followed by jpeg, png, gif, and other image formats)
Imagejpeg ($ img); // output image
ImageDestroy ($ img); // release the memory and complete the creation.
?> |