PHP image output: the code is as follows,
// Step 1: Set the MIME type and output format
Header ("Content-Type: image/png ;");
For ($ I = 0; $ I <4; $ I ++)
{
$ Nmsg. = dechex (mt_rand (0, 15 ));
}
Echo $ nmsg;
// Create a blank area in step 2
$ Im = imagecreatetruecolor (200,200 );
// Create imagecolorallocate in step 3 to fill the image color
$ Blue = imagecolorallocate (USD im, 0,102,255 );
// Fill the blue color with the background in step 4
Imagefill ($ im, 0, 0, $ blue );
// Fill in the text in step 5
$ White = imagecolorallocate ($ im, 255,255,255 );
Imagestring ($ im, 5, 80, 80, $ nmsg, $ white );
// Step 6 first, let's take a look at the effect.
Imagepng ($ im );
// Destroy and keep the memory
Imagedestroy ($ im );
?>
Reply to discussion (solution)
The error is:
There is a problem with the FOR loop. I output a verification code and put $ nmsg. = dechex (mt_rand. if this parameter is removed, a verification code is displayed, and an error is returned.
Declare the $ nmsg variable before the for loop:
$nmsg = "";
/Step 1: Set the MIME type and output format
Header ("Content-Type: image/png ;");
$ Nmsg = '';
For ($ I = 0; $ I <4; $ I ++)
{
$ Nmsg. = dechex (mt_rand (0, 15 ));
}
// Echo $ nmsg;
In this way, you can.
Thank you!