I start the picture old display does not come out, show is a cracked picture, after the query found may be caused by the following several
1) in the header ("Content-type:image/png"), before adding the following code
Ini_set (' display_errors ', ' Off ');
I was caused by the above problem.
Attach the code for the picture that generated the verification code
<?php ini_set (' display_errors ', ' Off '); Header ("Content-type:image/png"); Session_Start (); $_session[' code '] = ' Null ';//initialize = ' $width '; $height = ' + ';//$code = '; $tmptext = '; $bordercolor = '; for ($i =0; $i <4; $i + +) {$tmptext = Rand (0,9); $code. = $tmptext;} $_session[' Code ' = $code;//The following three verses allow the browser not to cache @header ("expires:-1"); @header ("Cache-control:no-store,private,posc-check =0,pre-check=0,max-age=0 ", FALSE); @header (" Pragma:no-cache "); if (function_exists (' imagecreate ') && Function_exists (' Imagecolorset ') && function_exists (' imagecopyresized ') && function_exists (' Imagecolorallocate ') && function_exists (' Imagesetpixel ') && function_exists (' Imagechar ') && Function_exists (' imagecreatefromgif ') && function_exists (' imagepng ')) {$im = Imagecreate ($width, $height); $ BackgroundColor = Imagecolorallocate ($im, 255, 255, 255); $numorder = Array (1,2,3,4);/**shuffle will disturb the array */shuffle ($ Numorder);/**array_flip returns an array that is reversed, the key value is processed by the value */$numorder = Array_flip ($numorder);X= '; $y = '; $text _color = '; for ($i =1; $i <=4; $i + +) {$x = $numorder [$i] * + mt_rand (0,4)-2; $y = Mt_rand (0,3); $text _col or = Imagecolorallocate ($im, Mt_rand (50,255), Mt_rand (50,255), Mt_rand (50,255)),/** draws characters in $im, 5 indicates the size of the font $x +5 */ Imagechar ($im, 5, $x +5, $y +3, $code [$numorder [$i]], $text _color);} $linenums = Mt_rand (10,32); for ($i =0; $i <= $linenums; $i + +) {$linecolor = Imagecolorallocate ($im, 255, Mt_rand (0,255), Mt_rand (0,255)); $linex = Mt_rand (0,255); $liney = Mt_rand (0,255); Imageline ($im, $linex, $liney, $linex +mt_rand (0,4)-2, $liney +mt_rand (0,4)-2, $linecolor);} for ($i =0; $i <40; $i + +) {$pointcolor = Imagecolorallocate ($im, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255)); Imagesetpixel ($im, Mt_rand (0, $width), Mt_rand (0, $height), $pointcolor);} $bordercolor = Imagecolorallocate ($im, Imagerectangle, 1,, $height-1, $bordercolor) ($im, 0, 0, $width); Imagepng ($im); Imagedestroy ($im);}? >
2) Variable not initialized
3) in the header ("Content-type:image/png"), before adding
Ob_clean ();
The 23rd method does not ensure that the problem can be resolved, for informational purposes only.
Solve the problem of the PHP session verification code is not realistic