Why can't I output a picture session_start (); // number of random codes // $ _ rnd_code & nbsp ;=& nbsp; 4; // create random codes for ($ I = 0; $ I & lt; 4; $ I ++) {$ _ nmsg. = dechex (mt_rand ();} // Save the session. Why can't I output an image?
Session_start ();
// Number of random codes
// $ _ Rnd_code = 4;
// Create a random code
For ($ I = 0; $ I <4; $ I ++ ){
$ _ Nmsg. = dechex (mt_rand (0, 15 ));
}
// Save the session
$ _ SESSION ['code'] =$ _ nmsg;
// Length and height
$ _ Width = 75;
$ _ Height = 25;
// Create an image
$ _ Img = imagecreatetruecolor ($ _ width, $ _ height );
// Output image
Header ('content-Type: image/png ');
Imagepng ($ _ img );
The output result is
------ Solution --------------------
Notice: Undefined variable: _rnd_code in D:\AMP\web\ide_tmp.php on line 53
Warning: Division by zero in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _heght in D:\AMP\web\ide_tmp.php on line 53
Warning: mt_rand(): max(0) is smaller than min(1) in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _rnd_code in D:\AMP\web\ide_tmp.php on line 53
Warning: Division by zero in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _heght in D:\AMP\web\ide_tmp.php on line 53
Warning: mt_rand(): max(0) is smaller than min(1) in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _rnd_code in D:\AMP\web\ide_tmp.php on line 53
Warning: Division by zero in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _heght in D:\AMP\web\ide_tmp.php on line 53
Warning: mt_rand(): max(0) is smaller than min(1) in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _rnd_code in D:\AMP\web\ide_tmp.php on line 53
Warning: Division by zero in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _heght in D:\AMP\web\ide_tmp.php on line 53
Warning: mt_rand(): max(0) is smaller than min(1) in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _rnd_code in D:\AMP\web\ide_tmp.php on line 53
Warning: Division by zero in D:\AMP\web\ide_tmp.php on line 53
Notice: Undefined variable: _heght in D:\AMP\web\ide_tmp.php on line 53
Warning: mt_rand(): max(0) is smaller than min(1) in D:\AMP\web\ide_tmp.php on line 53
‰PNG
Modify by error message
Then you need:
Still unfriendly "verification code" image
------ Solution --------------------
Comment out the header and open the error to see the error.