PHP Why the captcha must be turned on Ob_clean to display
Ob_clean ();
Header ("Content-type:image/jpeg");
Generate Verification Code
$char = ' 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
$len = 4;
$schar = ";
$charlen = strlen ($char);
$schar. = $char [rand (0, $charlen)];
}
Save the results to the session
@session_start ();
$_session[' captcha_code '] = $schar;
Reading pictures
$BG _file = './captcha/captcha_bg '. Mt_rand (1,5). '. jpg ';
Create a canvas based on a picture
$img = Imagecreatefromjpeg ($bg _file);
if (rand) = = 1) {
$color = imagecolorallocate ($img, 0, 0, 0);
}else {
$color = Imagecolorallocate ($img, 255, 255, 255);
}
$imgsize = getimagesize ($bg _file);
Imagestring ($img, 5, 0, $schar, $color);
Imagepng ($IMG);
Imagedestroy ($IMG);
I novice just start learning, verification code if not open Ob_clean (); is an X, the config file GD Library has been opened and restarted Apache. Want to know the guidance and explain why.
------to solve the idea----------------------
First put
Ob_clean ();
Switch to the form below and see if there's any output.
$data = Ob_get_contents ();
Ob_clean ();
Var_dump ($data);
------to solve the idea----------------------
This means that your program has output in front of it,