PHP application solution

Source: Internet
Author: User
Tags getcolor
I am a beginner in the use of PHP classes. I have found a class on the Internet that generates verification codes, how can I output the verification code generated by the class where the verification code needs to be output? The code in the class is as follows: & lt ;? Php & nbsp; classAuthCode & nbsp; {Use of PHP classes
I am a newbie. I just got started with the concept of class. now I have found a verification code generation class on the internet. how can I output the verification code generated in the class where I need to output the verification code? The code in the class is as follows:
Class AuthCode
{
Var $ image;
Var $ sBgcolor;
Var $ nWidth;
Var $ nHeight;
Var $ nLen;
Var $ bNoise;
Var $ nNoise;
Var $ bBorder;
Var $ aFontlist;
Function AuthCode ()
{
$ This-> sBgcolor = "# FFFFFF ";
$ This-> nWidth = 70;
$ This-> nHeight = 25;
$ This-> nLeftMargin = 5;
$ This-> nRightMargin = 5;
$ This-> nTopMargin = 3;
$ This-> nBottomMargin = 2;
$ This-> nLen = 4;
$ This-> bNoise = true;
$ This-> nNoisePoint = 50;
$ This-> nNoiseLine = 5;
$ This-> bBorder = true;

$ This-> aFontlist = "arial. ttf ";
}

Function OutputImg ()
{
$ This-> image = "";
$ This-> image = imagecreate ($ this-> nWidth, $ this-> nHeight );
$ Back = $ this-> getcolor ($ this-> sBgcolor );
Imagefilledrectangle ($ this-> image, 0, 0, $ this-> nWidth, $ this-> nHeight, $ back );
$ Size = ($ this-> nWidth-$ this-> nLeftMargin-$ this-> nRightMargin)/$ this-> nLen;
If ($ size> ($ this-> nHeight-$ this-> nTopMargin-$ this-> nBottomMargin ))
$ Size = $ this-> nHeight-$ this-> nTopMargin-$ this-> nBottomMargin;

$ Left = ($ this-> nWidth-$ this-> nLen * ($ size + $ size/10)/2 + $ this-> nLeftMargin;
$ Code = "";
For ($ I = 0; $ I <$ this-> nLen; $ I ++)
{
$ Randtext = rand (0, 9 );
$ Code. = $ randtext;
$ TextColor = imagecolorallocate ($ this-> image, rand (0,100), rand (0,100), rand (0,100 ));
$ Font = $ this-> aFontlist;
$ Randsize = rand ($ size-$ size/10, $ size + $ size/10 );
$ Location = $ left + ($ I * $ size + $ size/10 );
Imagettftext ($ this-> image, $ randsize, rand (-18, 18), $ location, rand ($ size, $ size + $ size/5) + $ this-> nTopMargin, $ textColor, $ font, $ randtext );
}
If ($ this-> bNoise = true) $ this-> setnoise ();
$ _ SESSION ['yzm'] = md5 ($ code );
$ Bordercolor = $ this-> getcolor ("# FFFFFF ");
If ($ this-> bBorder = true) imagerectangle ($ this-> image, 0, 0, $ this-> nWidth-1, $ this-> nHeight-1, $ bordercolor );
Header ("Content-type: image/png ");
Imagepng ($ this-> image );
Imagedestroy ($ this-> image );
}
Function setnoise () // sets the noise.
{
For ($ I = 0; $ I <$ this-> nNoiseLine; $ I ++ ){
$ RandColor = imagecolorallocate ($ this-> image, rand (0,255), rand (0,255), rand (0,255 ));
Imageline ($ this-> image, rand (0, $ this-> nWidth), rand (0, $ this-> nHeight), rand (0, $ this-> nWidth), rand (0, $ this-> nHeight), $ randColor );
}

For ($ I = 0; $ I <$ this-> nNoisePoint; $ I ++ ){
$ RandColor = imagecolorallocate ($ this-> image, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ this-> image, rand (0, $ this-> nWidth), rand (0, $ this-> nHeight), $ randColor );

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.