Why the captcha must be turned on Ob_clean in PHP to display

Source: Internet
Author: User
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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.