Why does ob_clean need to be enabled for the verification code in php?-php Tutorial

Source: Internet
Author: User
Why is ob_clean required to display the verification code in php?
Ob_clean (); header ("content-type: image/jpeg"); // Generate the verification code $ char = '1234567890abcdefghijklmnopqrstuvwxyz '; $ len = 4; $ schar = ''; $ charlen = strlen ($ char); for ($ I = 0; $ I <$ len; $ I ++) {$ schar. = $ char [rand (0, $ charlen)];} // Save the result to the session @ session_start (); $ _ SESSION ['captcha _ Code'] = $ schar; // Read Image $ bg_file = '. /captcha/captcha_bg '. mt_rand (1, 5 ). '.jpg '; // Create a canvas based on the image $ img = imagecreatefromjpeg ($ bg_file); if (rand (1, 2) = 1) {$ color = imagecolorallocate ($ img, 0, 0, 0);} else {$ color = imagecolorallocate ($ img, 255,255,255);} $ imgsize = getimagesize ($ bg_file); imagestring ($ img, 5, 30, 0, $ schar, $ color); imagepng ($ img); imagedestroy ($ img );


I am a newbie who just started learning the verification code. if ob_clean () is not enabled, it is an X. The GD library of the configuration file has been enabled and apache is restarted. I hope to know the instructions and explain the reasons.


Reply to discussion (solution)

First
Ob_clean ();
Switch to the following format to see if there is any output

$data = ob_get_contents();ob_clean();var_dump($data);

This indicates that there is output in front of your program,

This indicates that there is output in front of your program,

Thank you for solving the problem. it is true that you have added blank lines to the front.

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.