Verification code garbled

Source: Internet
Author: User
I have written a verification code class for garbled verification codes. to help you find errors, I posted the class code in the encoding format gbk & lt ;? Phpheader (& quot; Content-type: image/png; charset = gbk & quot;); classCheckCode {private $ mCheckCodeNum = 4; pr verification code garbled
I wrote a verification code class. to help you find errors, I pasted the class code in the encoding format gbk.

Header ("Content-type: image/png; charset = gbk ");
Class CheckCode {
Private $ mCheckCodeNum = 4;
Private $ mCheckCode = '';
Private $ mCheckImage = '';
Private $ mDisturbColor = '';
Private $ mCheckImageWidth = '80 ';
Private $ mCheckImageHeight = '20 ';
Public function CreateCheckCode ()
{
$ This-> mCheckCode = strtoupper (substr (md5 (rand (), 0, $ this-> mCheckCodeNum ));
Return $ this-> mCheckCode;
}

Private function CreateImage ()
{
$ This-> mCheckImage = @ imagecreate ($ this-> mCheckImageWidth, $ this-> mCheckImageHeight );
Imagecolorallocate ($ this-> mCheckImage, 200,200,200 );
Return $ this-> mCheckImage;
}

Private function SetDisturbColor ()
{
For ($ I = 0; $ I <= 128; $ I ++)
{
$ This-> mDisturbColor = imagecolorallocate ($ this-> mCheckImage, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ this-> mCheckImage, rand (2,128), rand (), $ this-> mDisturbColor );
}
}

Public function SetCheckImageWH ($ width, $ height)
{
If ($ width = ''| $ height ='') return false;
$ This-> mCheckImageWidth = $ width;
$ This-> mCheckImageHeight = $ height;
Return true;
}

Private function WriteCheckCodeToImage ()
{
For ($ I = 0; $ I <= $ this-> mCheckCodeNum; $ I ++)
{
$ Bg_color = imagecolorallocate ($ this-> mCheckImage, rand (0,255), rand (0,128), rand (0,255 ));
$ X = floor ($ this-> mCheckImageWidth/$ this-> mCheckCodeNum) * $ I;
$ Y = rand (0, $ this-> mCheckImageHeight-15 );
Imagechar ($ this-> mCheckImage, 5, $ x, $ y, $ this-> mCheckCode [$ I], $ bg_color );
}
}

Public function OutCheckImage ()
{
$ This-> CreateCheckCode ();
$ This-> CreateImage ();
$ This-> SetDisturbColor ();
$ This-> WriteCheckCodeToImage ();
Imagepng ($ this-> mCheckImage );
Imagedestroy ($ this-> mCheckImage );
}
}
?>

Define output in this page
$ C_check_code_image = new CheckCode ();
$ C_check_code_image-> OutCheckImage ();
All are completely normal. a verification code is displayed normally.
However, after I create a PHP page and add the include class, garbled characters will appear when I put the above two statements. the error code prompts Warning: cannot modify header information-headers already sent by (output started at E: \ www \ HSreport \ check_code.php: 1) in E: \ www \ HSreport \ class \ CheckCode. class. php on line 2
Running ng ihdrp-J? Why does one's LTE hit the limit? Habitat vortex? $ Commandid 000000008 00000000m '? Y? 6e 4 ??? 5 &"? "H ╗ xw '[? "? * Why # When does one fail? 7 blank D blank ?? Why ^ I % why M8? A challenge?> 'Commandid ?? I8workflow? WiAg & zookeeper ub snapshot U? Repeated] repeated bytes &, A | t ?, Why [why? ? Why C? Why? 4EG commandid | commandid L? L ready h! Parameters?.?> E ?)?? When 3 then? Why McQ ?? Why? -X linear regression? Zookeeper "? UE ^? QJR %? G branch? Xu/Hangzhou T branch a branch, 7- <嘽墦超?聻? ?蓲遥jY l.D1 噥?.剼囃@T鱝O6( ?#檱臔4箐pG ? 洜葵0@~i捦?貝?&?The same is true on the login page. ask for help.

------ Solution --------------------
The call page you created has a BOM header, which is output before header ().
Solution
------ Solution --------------------
Check whether the encoding of each page is the same, and whether there is an output statement before the header!

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.