/**
* Make Verification code
*. Start session
Set the header
Create a canvas
Create colors
Create random numbers and place them on the canvas
*6. Placing a number of random numbers in the session
*7. Adding interference points or interference lines
*8. Output Canvas
*9. Destroying Canvas Resources
*/
1. Start session
Session_Start ();
2. Set the header to specify the MIME output type
Header (' content-type:image/png ');
3. Create a canvas
$width = 100;
$height = 30;
$im = Imagecreate ($width, $height);
4. Create colors
$bgcolor = Imagecolorallocate ($im, 255,255,255);
$textcolor = Imagecolorallocate ($im, 0,255,255);
$randcolor = Imagecolorallocate ($im, Mt_rand (0,200), Mt_rand (0,200), Mt_rand (0,200));
5. Create a random number and place it on the canvas
$verify =null;
for ($i =0; $i <4; $i + +) {
$temp = Mt_rand (0,9);
$verify. = $temp;
Imagestring ($im, 5, $i *15+15,8, $temp, Imagecolorallocate ($im, Mt_rand (0,200), Mt_rand (0,200), Mt_rand (0,200));
}
6 put the generated random number in session
$_session[' verify '] = $verify;
7. Adding interference points
for ($i =0; $i <100; $i + +) {
Imagesetpixel ($im, rand (0, $width), rand (0, $height), Imagecolorallocate ($im, Rand (100,255), Rand (100,255), Rand ( 100,255)));
}
8. Export the image
Imagepng ($im); Imagegif ()
9. Destroying an image
Imagedestroy ($im);
?>